As a follow-up to my recent post which showed how to send an email in .NET, there are some circumtances where you would need to use SMTP authentication. In fact, my guess is that this is the norm. So: here’s how you would do that:
System.Web.Mail.MailMessage em = new MailMessage() ;
string UserName = “joe@joeblogs.com” ;
string Password = “******” ;
em.Body = “This is the body of the email” ;
em.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
em.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", UserName); //set your username here
em.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", PassWord); //set your password here
// blogged with BlogJet