Simple .NET 2.0 mail utility

Printer Friendly Version

This is the simplest way I could come up with to send an email, assuming that your credentials are good for the local Exchange Server.

using System.Net.Mail;
namespace PAB.Utils
public class MailUtil
private MailUtil() { }
public static void SendMail(string smtpServer, string fromAddress, string toAddress, string subject, string body)
System.Net.Mail.SmtpClient test = new System.Net.Mail.SmtpClient();
test.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
test.UseDefaultCredentials = true;
test.Host = smtpServer;

Submission Date:  1/17/2006 3:27:19 PM
Submitted By:  Peter Bromberg
My Home Page:

My Biography
Pete is a consultant / architect and "UnEducator" using .NET. His samples at GotDotNet have been downloaded over 42,000 times. He enjoys jazz / classical music, digital photo artistry using Maya, fine wines and the beach. Pete is the co-founder / co-developer of, and a Microsoft C# MVP and MCP. Read Peter's UnBlog at