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.Subject = "Test Mail";
outmail.Body="Test Body";

//Finally send the mail.

Refer for more details

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: