Search code examples
outlookoutlook-addincreateobjectmailitem

which is the better way to create an object of Outlook MaiItem


I found two ways to create an object of Outlook mailItem

Outlook.MailItem oMsg = (Outlook.MailItem)Globals.ThisAddIn.Application.CreateItem(Outlook.OlItemType.olMailItem);

and

 Outlook.Application oApp = new Outlook.Application();
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);

What is the diffrence between these two codes and Which one is better and secure?


Solution

  • If your code is in a COM addin, the first one is the one and only way to do it - use the Outlok.Application object passed to your addin instead of creating a new instance. COM addins are trusted, and the Outlok.Application object is not crippled by the security prompts.