SMTP Authentication Using System.Web.Mail [ aka CDOSYS ]
Code example below demonstrates how to send mail to SMTP server that requires authentication. In order to do this you can always buy 3rd party component. However CDOSYS Schema is accessible directly from your ASP.NET code and you can use MailMessage.Fields to manipulate it.
void SentAuthEmail(string username, string password) { MailMessage oMsg = new MailMessage(); oMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1); oMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", username); oMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", password); oMsg.From = "somebody@somemail.com"; oMsg.To = "somebody@somemail.com"; oMsg.Body = "Hello!"; SmtpMail.Send(oMsg); }
Update: This tip is more relevant for ASP.NET 1.1. ASP.NET 2.0 has much more advanced mechanism under System.Net.
Friday, January 16, 2004 7:04 PM