to expand on Idriss's answer, here's my static method that works like a champ:
using System.Web.Mail;
public static void SendEmail(String Subject, String sMessage, String EmailAddress, String STMPServer, int SMTPPort, String UserName = "", String Password = null, Boolean IsSecure = true, Boolean IsHTML = true, String FromAddress = "no-reply@contoso.com") {
string SMTP_SERVER = "http://schemas.microsoft.com/cdo/configuration/smtpserver";
string SMTP_SERVER_PORT = "http://schemas.microsoft.com/cdo/configuration/smtpserverport";
string SEND_USING = "http://schemas.microsoft.com/cdo/configuration/sendusing";
string SMTP_USE_SSL = "http://schemas.microsoft.com/cdo/configuration/smtpusessl";
string SMTP_AUTHENTICATE = "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate";
string SEND_USERNAME = "http://schemas.microsoft.com/cdo/configuration/sendusername";
string SEND_PASSWORD = "http://schemas.microsoft.com/cdo/configuration/sendpassword";
MailMessage mail = new MailMessage();
mail.Fields[SMTP_SERVER] = STMPServer;
mail.Fields[SMTP_SERVER_PORT] = SMTPPort;
mail.Fields[SEND_USING] = 2;
mail.Fields[SMTP_USE_SSL] = IsSecure;
if(!String.IsNullOrEmpty(UserName) && !String.IsNullOrEmpty(Password))
{
mail.Fields[SMTP_AUTHENTICATE] = 1;
mail.Fields[SEND_USERNAME] = UserName;
mail.Fields[SEND_PASSWORD] = Password;
}
else
{
mail.Fields[SMTP_AUTHENTICATE] = 0;
}
mail.From = FromAddress;
mail.To = EmailAddress;
mail.Subject = Subject;
if (IsHTML)
{
mail.BodyFormat = MailFormat.Html;
}
else
{
mail.BodyFormat = MailFormat.Text;
}
mail.Body = sMessage;
SmtpMail.Send(mail);
}