How To Send Email Using Microsoft OutLook In ASP.NET (C#)

In case a .Net application is running in an intranet server then there might be a situation that all the mail forwarding things should be done using the installed mail client and the configured email account.
In this case if your machine has Microsoft OutLook installed in it and you want to send mail using that OutLook instead of Gmail or any other SMTP providing clients then here is the code to do it.

Code to Send Email using Microsoft OutLook in C#

First your application need a reference to "Microsoft.Office.Interop.Outlook" namespace. Add it to your project by selecting the Assemblies tab and then Extensions inside it the modal. Then find out the namespace here.
Another namespace named "System.Net.Mail" will be needed in the application, so add it up. Here is the code block to send the email.
public bool SendEmailViaOutLook()
                // Create a Outlook Application and connect to outlook 
                Application OutlookApplication = new Application();

                // create the MailItem which we want to send 
                MailItem message = (MailItem)OutlookApplication.CreateItem(OlItemType.olMailItem);

                MailAddress toAddress = new MailAddress("[email protected]");
                MailAddress ccAddress = new MailAddress("[email protected]");

                message.To = toAddress.ToString();
                message.CC = ccAddress.ToString();
                message.Subject = "Mail Subject";
                message.Body = "Mail Body";
                message.BodyFormat = OlBodyFormat.olFormatHTML;

                //Send email

                return true;
            catch (System.Exception ex)
                return false;
In the above code the OutlookApplication object creates an Outlook Application instance and connect to outlook, and the mail item object get the network credentials and all required components to send email.
That's it ! You are done with the work.
Happy Coding...


  1. Hi i have implemented same thing in web application once this code was moved to server, it is not working because it is linking with outlook credentials locally...what are the change should be there if i want to make it as web application and host on server

    1. Hi Dinesh,

      This code will not work in servers as it is using the local outlook credentials. It will work over intranet applications. I would suggest you to use gmail SMTP or your personalized SMTP to sen out emails from a remotely hosted server.

      I am sure if you are using outlook then you must have the credentials of the mail account, then why don't you configure the SMTP for the perticular email account.

      I hope you got my point.

      Tapan kumar

    2. You can refer this article for setting up Gmail SMTP or any SMTP service provider.