1: namespace used
Using System. Net. Mail;
Using System. Net;
2: Implemented static class
Public static class SendMail
{
/// <Summary>
/// Send an email
/// </Summary>
/// <Param name = "to"> recipient email address </param>
/// <Param name = "from"> sender's email address </param>
/// <Param name = "subject"> subject </param>
/// <Param name = "body"> email content </param>
/// <Param name = "username"> the username used to log on to the smtp host. Note that it is the first part of the email address '@'. </param>
/// <Param name = "password"> User password used to log on to the smtp host </param>
/// <Param name = "smtpHost"> smtp host used for sending emails </param>
Public static void Send (string to, string from, string subject, string body, string userName, string password, string smtpHost)
{
MailAddress from1 = new MailAddress (from );
MailAddress to1 = new MailAddress ();
MailMessage message = new MailMessage (from1, to1 );
Message. Subject = subject; // set the mail Subject
Message. IsBodyHtml = true; // set the email body to html format.
Message. Body = body; // you can specify the email content.
SmtpClient client = new SmtpClient (smtpHost );
// Set the mail Sender authentication method
// Note that if the sender address is a abc@def.com, the user name is abc instead of the abc@def.com
Client. Credentials = new NetworkCredential (userName, password );
Client. Send (message );
}
}