Cannot initialise Recipient on Outlook MailItem in C# Winforms Application

0

I am writing a class to send out emails through Outlook 2013 (15.0.4859). I have Outlook open in the background.

I tried the widely used code:

// 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;

I get an error trying to initialise oRecips

Operation aborted (Exception from HRESULT: 0x80004004 (E_ABORT))

I tried doing:

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

but I get the same error.

How do I correctly specify recipients of the email?

c#
outlook
asked on Stack Overflow Mar 7, 2017 by NotCaring • edited Dec 19, 2019 by Uwe Keim

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0