How to create a new Outlook 2013 Email using C# in 3 simple steps

It has traditionally been quite painful to interact with any part of the Microsoft Office product family from a C# application, but thanks to the introduction of dynamics and optional parameters over recent years, the process has dramatically improved.

Step 1 – Prerequisites and Assembly References

Before doing anything, it is important to note that you must have Microsoft Office 2013 installed for this to work. Seems obvious, but, its still worth mentioning.

You also need two references;

Microsoft.Office.Core
Microsoft.Office.Interop.Office

The quickest way to add these references to your project is to right click on the References folder in your project, and click Add Reference. The Reference Manager dialog window will appear as shown below;

Reference Manager

  1. Click the COM tab
  2. Type Outlook into the search box
  3. Tick Microsoft Outlook 15.0 Object Library
  4. Click OK

You should now see that the appropriate references have been added to your project;

References

Step 2 – Using Directives and Initialization

Next, add the appropriate using directives to your code file.

using Microsoft.Office.Interop.Outlook;
using OutlookApp = Microsoft.Office.Interop.Outlook.Application;

The second directive is a recommendation to avoid ambiguity with other classes with the name Application.

In the constructor of your application (or wherever you want this code to go), create an instance of the Outlook Application and create a new MailItem object, as shown;

OutlookApp outlookApp = new OutlookApp();
MailItem mailItem = outlookApp.CreateItem(OlItemType.olMailItem);

Step 3 – Format and display the email to the user

Finally you can begin to flesh out your email.

mailItem.Subject = "This is the subject";
mailItem.HTMLBody = "<html><body>This is the <strong>funky</strong> message body</body></html>";

//Set a high priority to the message
mailItem.Importance = OlImportance.olImportanceHigh;

And to display the email, simply call the Display method;

mailItem.Display(false);

There are literally dozens of things you can do to an Outlook Email, including adding attachments, business cards, images, recipient, CC/BCC fields.

Summary

To create an Outlook 2013 email from C#, simply add the Microsft Outlook 15.0 Object Library to your solution, add the appropriate using directives, create a new Application object, and MailItem object, and flesh out your email. When ready, simply call MailItem.Display(false) to show the email to the user.

Please leave a comment below if you found this post useful

11 Comments

  • Dell Mercant

    January 20, 2014

    You can use CDO Object for sending email
    http://csharp.net-informations.com/communications/csharp-cdo-email.htm
    c# CDO email

    dell

    Reply
  • Shakil Makani

    October 23, 2014

    This is really helpful. Thank you!

    Reply
  • Besat Zardosht

    April 30, 2015

    Thank you for your post

    I get this error:

    Retrieving the COM class factory for component with CLSID failed due to the following error: 80040154 Class not registered

    Reply
    • Jon Preece

      May 1, 2015

      Please ensure that you are targeting ‘X86’ rather than ‘Any CPU’

      Reply
      • Besat Zardosht

        May 2, 2015

        Thank you for your reply. But I had tried X86 and it did not worked!

        The problem was that I need to install Outlook on the server too. After I installed Outlook on the server this error does not pop up but It timeout every time I tried to create an Outlook object:

        OutlookApp outlookApp = new OutlookApp();

        Reply
        • SANJAYBK

          November 25, 2015

          Beset, Did you find the soln for this? I have the same issue. Email window opens from local, but doesn’t work from IIS

          Reply
  • Ajay Aanjna

    May 22, 2015

    anyone have idea about add new pop3/imap account using redemption in outlook …thanks in advance

    Reply
  • Rahul

    March 2, 2016

    Hello,

    What i created a email item in outlook, it is coming as a compose email (New Email), all my details like to,cc,email body,subject is all coming in the textbox and have a option to send me.

    We want it to display as normal preview, how can we solve that?

    Regards
    Rahul

    Reply
  • Goga Hammer

    April 27, 2016

    Thank

    Reply
  • Pingback: How to create a Microsoft Outlook 2013 | pedro

  • Neha Parveen

    June 22, 2016

    How I can I know the delivery detail of the mail. If it got failed or successful?

    Reply

Leave a Reply