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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s