Search code examples
c#-4.0outlookoffice-interopoutlook-addinoutlook-2010

How to open Outlook's new mail window with prepopulated attachment


I need to open a new email window with a prepopulated attachment when a user clicks some button or link in my application.


Solution

  • Old question, but I also ran in to this so here's a copy and paste solution:

    Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();
    Microsoft.Office.Interop.Outlook.MailItem oMsg = (Microsoft.Office.Interop.Outlook.MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
    
    oMsg.Subject = "subject something";
    oMsg.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatHTML;
    oMsg.HTMLBody = "text body"; //Here comes your body;
    oMsg.Attachments.Add("c:/temp/test.txt", Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, Type.Missing, Type.Missing);
    oMsg.Display(false); //In order to display it in modal inspector change the argument to true
    

    You'll need to add a reference to the Microsoft.Office.Interop.Outlook component in your project.