Monday, September 28, 2009

Sending eMail using SmtpClient class

This sample code demonstrates how to send an email using the System.Net.Mail.SmtpClient class.

private bool sendMail(string strToAddress, string strFromAddress, string strSubject, string strBody)
{
// new instance of MailMessage
MailMessage mailMessage = new MailMessage();

// Sender Address
mailMessage.From = new MailAddress(strFromAddress);

// Recepient Address
mailMessage.To.Add(new MailAddress(strToAddress));

// Subject
mailMessage.Subject = strSubject;

// Body
mailMessage.Body = strBody;

// format of mail message
mailMessage.IsBodyHtml = true;

// new instance of Smtpclient
SmtpClient mailSmtpClient = new SmtpClient("smtpServer");

// mail sent
mailSmtpClient.Send(mailMessage);
}

0 Comments:

blogger templates | Make Money Online