DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Send Email Using C#

01.27.2012
| 1752 views |
  • submit to reddit
        // send email using c#.net

private void SendYourEmailFunction()
{
 MailMessage myMsg= new MailMessage();
  myMsg.To.Add("destination@test.com"); 
  myMsg.Bcc.Add("mymail@test.com");
  myMsg.Subject = "test mail"; 
  myMsg.From = new MailAddress("test@test.com");
  myMsg.Body = HttpUtility.HtmlDecode(messageContent); html format
  myMsg.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
  System.Net.NetworkCredential AuthInfo = new System.Net.NetworkCredential("mymail@test.com", "mypassword");
  smtp.Host = strSMTPServer; // smtp.yourdomain.com
  smtp.UseDefaultCredentials = false;
  smtp.Credentials = AuthInfo;
  smtp.Timeout = 20;
  smtp.Port = 25;
  smtp.EnableSsl = false;
  smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
   smtp.Send(myMsg);
}