Can only send email via Outlook if Outlook is open

I didn't like the idea to use Thread.Sleep for 5 seconds, so I've found another solution, that worked for me:

All you need is get Inspector object for newly created MailItem

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

Answer was published in Google groups originally for Outlook 2007 (but it worked for me with Outlook 2010)


The following code has reliably worked for months for me:

            app = new Microsoft.Office.Interop.Outlook.Application();
            Microsoft.Office.Interop.Outlook.NameSpace ns = app.GetNamespace("MAPI");
            f = ns.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
            Thread.Sleep(5000); // a bit of startup grace time.

if outlook was open it uses it, if not its opened it. Of course, if your outlook requires you to login, your code wont allow for that. Some systems make it difficult for you to auto login.