VerySimple Developer Blog
Technical Tips, Tricks and Rants.

Archive for November, 2007

 
Nov
01
Filed Under (.NET) by Jason on 01-11-2007

For whatever reason the web is filled with outdated examples of sending email with C#. This an example using .NET 2.0

First, be sure to import the Mail libs at the top of your class:

using System.Net.Mail;

Then in your code where the email will be sent:

MailMessage msg = new MailMessage();
msg.From = new MailAddress("from@address.com");
msg.To.Add(new MailAddress("to@address.com"));
msg.Subject = "message subject";
msg.Body = "message body";

SmtpClient smtp = new SmtpClient(”your.smtp.host”);
smtp.Send(msg);

That should do it. Feel free to post comments.

 

Close
  • Social Web

NOTE: Email is disabled

E-mail It