As the developer here at High Speed Web, I get to deal with customers on special occasions. Generally these entail stand-offs between the technical support staff (which may or may not include network administrators) and the customers. The latter states that the problem is the server, while the former contends that it is the user’s code. So they bring in me, to either slap the administrators for not setting up their servers right or to show the user what we like to call the correct way to code. During my time here, I have helped several people out with their ASP scripts as pertaining to sending email. They all used CDO, and they all had the same problem: SMTP Authentication.
SMTP Authentication is fairly simple to do in ASP with CDO, but it isn’t obvious or apparent. I don’t quite understand Microsoft’s methodology here, but here it is:
Set msgTest = CreateObject("CDO.Message")
msgTest.Subject = "Testing smtp authentication"
msgTest.Sender = "firstname.lastname@example.org"
msgTest.From = "email@example.com"
msgTest.To = "firstname.lastname@example.org"
msgTest.TextBody = "This is some sample message text.."
Pretty easy so far. Create a message object of type CDO.Message. Give it a subject, a sender, a from email address, a to email address, and some text as the body. Most everyone gets this part right. And then on…
'Tell it to use SMTP (1 is send using local SMTP pickup directory, 2 is SMTP server)
msgTest.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Name or IP of Remote SMTP Server
msgTest.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.your.com"
'Use SSL for the connection (False or True)
msgTest.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
msgTest.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
Most people get these right as well, but what they are lacking is this:
'Type of authentication, 0 = NONE, 1 = Basic (Base64 encoded), 2 = NTLM
msgTest.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
'Your UserID on the SMTP server
msgTest.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "youruserid"
'Your password on the SMTP server
msgTest.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "yourpassword"
Depending on your hosting provider, the user you use to send may be an email address. With our hosting customers it is. You will probably never use NTLM authentication, unless you do something on a corporate network with centralized authentication.
Well, that’s about it. It’s really straight forward, just some gotcha’s in the schemas and configuration fields.