SMTP Authentication in ASP.NET

Hi, I had faced a problem when sending mails from ASP.NET using .NET 1.0. My Exchange server needs authentication to send mails. Later found that .NET 1.0 doenst support authencation with an SMTP server. I had to switch over to .NET 1.1 to send mails. All which is required to add a few lines of code for authentication.

//This is a usual code
System.Web.Mail.MailMessage msg = new System.Web.Mail.MailMessage();
msg.Subject = “Test Subject”;
msg.Body = “Sample Body Message”;
msg.From = yourname@domain.com;
msg.To = someone@domain.com;
System.Web.Mail.SmtpMail.SmtpServer = “EXCHANGESERVER”;
System.Web.Mail.SmtpMail.Send( msg );

//Add this line of code for authentication.
msg.Fields.Add(“http://schemas.microsoft.com/cdo/configuration/smtpauthenticate”,2);
where the 2 specifies NTLM, 1 for basic, 0 for none.

Leave a comment