The blog and home page of Simon Soanes
Skip to content
[ Log On ]

This is a quick and easy one for anyone else trying to send mail using ASP.NET.

First, add the using statement for the appropriate namespace:

using System.Web.Mail;

Then, create a MailMessage object:

MailMessage m = new MailMessage();
m.From = "";
m.Subject = "A demo message";
m.Body = "This is the body\n\n-Simon";
m.To = "";

And then, finally - send it using the static method off SmtpMail:


Another example of why .NET rocks, what used to be an annoyingly complex task is now suddenly relegated to being easy as anything...

(This article is to make up for this monster article which discusses opening file handles on physical devices...)