The Darkside

Shedding light on things and stuff

 
  Home :: Contact :: Syndication  :: Login
  75 Posts :: 0 Stories :: 49 Comments :: 2 Trackbacks

Ads

Archives

Post Categories

Open Source Projects

Other Blogs

This is a very simple method of sending SMTP mail using C#. Some points that are of intereset are the "To", "CC" and "BCC" collections, that allow multiple addresses to be added.

MailMessage mailMessage = new MailMessage();

 

SmtpClient smtpClient = new SmtpClient();

mailMessage.From = new MailAddress("from@mymail.com");

mailMessage.To.Add(new MailAddress("to@mymail.com"));

mailMessage.CC.Add(new MailAddress("cc1@mymail.com"));

mailMessage.Bcc.Add(new MailAddress("bcc1@mymail.com"));

mailMessage.Subject = "My SMTP Mail";

 

mailMessage.Body = "This is the body of the mail";

 

//smtpClient.Host = "127.0.0.1";

//smtpClient.Port = 25;

//smtpClient.UseDefaultCredentials = false;

 

smtpClient.Send(mailMessage);

Also, you will noticed the programmatic configuration if the SMTP Client object has been commented out. You can configure this in the application configuration file, by adding a section like the following: 

<system.net>

    <mailSettings>

        <smtp from="from@mymail.com">

            <network host="127.0.0.1" port="25" defaultCredentials="false" />

        </smtp>

    </mailSettings>

</system.net>

You can also configure parameters such as the username and password that the SMTP client should use when loggin on to the server. These are attributes of the <network> node.

 

posted on Wednesday, August 08, 2007 2:12 PM

Feedback

# re: Sending SMTP mail in C# 8/10/2007 7:59 AM Darksider
This site shows a really useful way of embedding images in SMTP mail - http://mikepope.com/blog/DisplayBlog.aspx?permalink=1264

Comments have been closed on this topic.