14

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

Community
  • 1
  • 1
Selvakumar
  • 360
  • 1
  • 3
  • 17

2 Answers2

30

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.

Peter
  • 3,916
  • 1
  • 22
  • 43
3

you can do it using interop services of outlook

using Outlook = Microsoft.Office.Interop.Outlook;

 Outlook.MailItem mail = Application.CreateItem(
        Outlook.OlItemType.olMailItem) as Outlook.MailItem;
    mail.Subject = "Quarterly Sales Report FY06 Q4";
    Outlook.AddressEntry currentUser =
        Application.Session.CurrentUser.AddressEntry;
    if (currentUser.Type == "EX")
    {
        Outlook.ExchangeUser manager =
            currentUser.GetExchangeUser().GetExchangeUserManager();
        // Add recipient using display name, alias, or smtp address
        mail.Recipients.Add(manager.PrimarySmtpAddress);
        mail.Recipients.ResolveAll();
        mail.Attachments.Add(@"c:\sales reports\fy06q4.xlsx",
            Outlook.OlAttachmentType.olByValue, Type.Missing,
            Type.Missing);
        mail.Send();
    }

Working example can be found here..

Saghir A. Khatri
  • 3,429
  • 6
  • 45
  • 76
Jigar Pandya
  • 6,004
  • 2
  • 27
  • 45
  • 8
    So this look like it uses outlook to actually send the mail in the background. The question is asking how to actually open the new message window with an attachment already attached, leaving me the option to add to the email before sending it. – Sinaesthetic Sep 15 '15 at 05:15
  • Finally someone has the same concern as me. I created the temporary excel from a GridView. I would like to only open a new outlook message with the excel attached and let the user press Send. – Si8 Feb 22 '16 at 15:06