navigation
 Friday, March 31, 2006

In .NET 1.1 we always had a problem using the built in Mail class in the System.Net namespace whenever the mail server was on a different server than the authenticating web server because it lacked the authentication feature to the SMTP that allows for this to be transfered correctly.  So we always ended up using a 3rd party component like ASPNETEMAIL which worked pretty well for us.
With the release of .NET 2.0 obviously Microsoft worked on that feature and added the authentication feature to the Mail class. 
This is simple code to show how easy now it is to make this work in .NET 2.0

1 System.Net.Mail.MailMessage Email = new System.Net.Mail.MailMessage ("spamMe@falafel.com", "SpamThis@falafel.com");
2 Email.Subject = "test subject";
3 Email.Body = "this is a test";
4 System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient();
5 //This object stores the authentication values
6 System.Net.NetworkCredential basicAuthenticationInfo = new System.Net.NetworkCredential ("username", "password");
7 mailClient.Host = "mail.falafel.com";
8 mailClient.UseDefaultCredentials = false;
9 mailClient.Credentials = basicAuthenticationInfo;
10 mailClient.Send(Email);