PDC Code Update

Since one of the attendees at my PDC pre-con asked about this, I thought I'd pass it along. I've updated the sample code from my ASP.NET Overview pre-con session to add the necessary code for performing authentication when sending mail using an SMTP server that requires authentication (and requiring authentication for your SMTP server is a Good Thing®).

System.Web.Mail is just a wrapper over CDOSYS, and the v1.1 framework provides a new Fields member (on the MailMessage class) that provides access to any fields available in CDOSYS, by specifying the namespace for that field (more info on the fields available can be found here). So the code for authenticating a mail request is:

  'Use the following fields to add authentication, if necessary
  '0 = None / 1 = Basic / 2 = NTLM
  Mail.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
  Mail.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "myUser"
  Mail.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "myPwd"

Do keep in mind that when using basic authentication, credentials are passed in clear text, so it is especially important to make use of SSL encryption if you are using basic authentication.

Thanks to Darren Jefford, from Microsoft UK, for working this out.

1 Comment

Comments have been disabled for this content.