Saturday, July 24, 2010

How to Send mail through outlook using .NET application

Sending mail through outlook using .NET application becoming very easy now a days. It is a matter of few lines of code.
I have given you the sample code below

//Create the outlook application object
Outlook.Application outlookapp = new Outlook.Application();

//Create the Outlook Mail item object using the above outlook application object
//We can create appointment, Contact, Note, Task, Journal, Post using the aoove outllok application object
Outlook.MailItem outmail = (Outlook.MailItem)outlookapp.CreateItem(OlItemType.olMailItem);

//In the mail item add the recipients. We can add multiple recipients
outmail.Recipients.Add("name@domain.com");
outmail.Subject = "Test Mail";
outmail.Body="Test Body";

//Finally send the mail.
outmail.Send();

Refer for more details
http://msdn.microsoft.com/en-us/library/aa289167(VS.71).aspx

Note : When we add the receipt, a outlook warning message saying 'A program is trying to access e-mail addressess you have stored in Outlook.Do you want to allow this?' will be asked for security purpose.

No comments: