Monday, June 22, 2009

C# Send mail - Windows application

Outlook.Application oApp = new Outlook.Application();

//Create the new message by using the simplest approach.
Outlook.MailItem oMsg= Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);

//Add a recipient
Outlook.Recipient oRecip;
oRecip = (Outlook.Recipient)oMsg.Recipients.Add("xyz@xyz.com");

//Set the basic properties.
oMsg.Subject = "Payment received";
oMsg.Body = "Dear Sir, We have received payment for your order";

//Send the message.
oMsg.Save();
oMsg.Send();

//Explicitly release objects.
oRecip = null;
//oAttach = null;
oMsg = null;
oApp = null;

0 comments: