Tuesday, September 30, 2008

Send Email - Desktop Environment - C#

include name space "using System.Net.Mail;"

make function say sendmail in that,

sendmail()
{

// Details of SMTP server.
SmtpClient MailObj= new SmtpClient(SMTP_Server);

//Define USER ID and Password for SMTP Server Account
NetworkCredential cred = new NetworkCredential(SMTP_Authentication_User, SMTP_Authentication_Password);

//Assign that Credentials to Mail Object
MailObj.Credentials = cred;

//Define the email details as below.
//Note that multiple email address for to can be given by "," sign
MailObj.Send(from, to, subject, body);

}