Trying to Programmatically Create & Open a new Outlook Email

后端 未结 3 1854
你的背包
你的背包 2021-01-01 22:58

I have a winforms application and I am trying to create a method that will create and open a new Outlook Email. So far I have

private void CreateOutlookEmai         


        
相关标签:
3条回答
  • 2021-01-01 23:52

    Try this

    string subject = "My subject";
    string emailTag = string.Format("mailto:someone@test.com?subject={0}", subject);
    System.Diagnostics.Process.Start(emailTag);
    
    0 讨论(0)
  • 2021-01-01 23:55

    Think about it. You are calling the CreateItem method on this current object. Have you defined the CreateItem method in this class?

    Instead of your:

    Outlook.MailItem mailItem = (Outlook.MailItem) this.CreateItem(Outlook.OlItemType.olMailItem);
    

    You need the lines:

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

    You create an instance of the outlook application, on which you can call the CreateItem method.

    Edit

    There are two more things to make this work properly.

    1) Add a reference to the Microsoft.Office.Interop.Outlook package to your project

    2) Ensure you have the appropriate using statement in your class

    using Outlook = Microsoft.Office.Interop.Outlook;
    
    0 讨论(0)
  • 2021-01-01 23:56

    In my experience Office.Interop can be troublesome and simply kicking off Outlook with the appropriate arguments may represent a simpler and more portable option:

    System.Diagnostics.Process.Start("C:\\Program Files (x86)\\Microsoft Office\\Office12\\OUTLOOK.EXE", "/c ipm.note /m name@address.com"));
    

    Outlook command line switches give you many more options with numerous sources of info (try http://www.outlook-tips.net/how-to/using-outlook-command-lines)

    0 讨论(0)
提交回复
热议问题