Can only send email via Outlook if Outlook is open

后端 未结 2 485
南笙
南笙 2020-12-03 08:23

I want to use send emails via Outlook as described here. It works fine as long as I have already opened Outlook. So for example if Outlook is minimized and I execute my code

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-03 08:35

    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)

提交回复
热议问题