无法在C#Winforms应用程序中初始化Outlook MailItem上的收件人

时间:2017-03-07 14:39:16

标签: c# outlook

我正在编写一个课程,通过Outlook 2013(15.0.4859)发送电子邮件。我在后台打开Outlook。

我尝试了广泛使用的代码:

            // Create the Outlook application.
            Outlook.Application oApp = new Outlook.Application();


            // Create a new mail item.
            Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);

            // Set HTMLBody. 
            //add the body of the email
            oMsg.HTMLBody = "Test";
            //Subject line
            oMsg.Subject = "Test Subject";
            // Add a recipient.

            Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
            // Change the recipient in the next line if necessary.
            Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add("name@domanin.com");
            oRecip.Resolve();
            // Send.
            oMsg.Send();
            // Clean up.
            oRecip = null;
            oRecips = null;
            oMsg = null;
            oApp = null;

尝试初始化oRecips

时出错
            Operation aborted (Exception from HRESULT: 0x80004004 (E_ABORT))

我试过

            oMsg.Recipients.Add("name@domain.com") 

但我得到同样的错误。

如何正确指定电子邮件的收件人?

0 个答案:

没有答案