Wednesday, February 11, 2009

IIS 7 ASP scripts (vbscript) fail to send email (web.com)

I recently had a horrible experience with web.com. They "upgraded" our web server that broke all my client's email functionality for his ASP scripts. These scripts ran flawlessly for years without issue, then all of the sudden none of them worked, and the web host seemed unwilling to help us.

After doing some research, I discovered that they upgraded their servers to MS IIS 7, which no longer directly supports sending emails from an ASP page using "CDO.Message" or "CDONTS". I'm hoping that other web.com users might come across this article in a google search and could save some themselves some time. There might also be other people who have another web host with similar problems.

From what I understand, according to all articles I have found around the web, IIS7 no longer supports sending emails from an ASP page using "CDO.Message" directly.

Here is my old code, which no longer works:

Sub SendMail(Subject,Body,EmailTo,EmailFrom)
Set Newmail = CreateObject("CDO.Message")
newmail.TextBody = Body
newmail.Subject = Subject
newmail.To = EmailTo
newmail.From = EmailFrom
newmail.Send
set newmail = nothing
end Sub


There are a few solutions out there, but the one that worked for me (as a web.com user) is to use CDOSYS. I found this through a series of searches, and my solution I present is just my flavor of the method recommended:

Regarding the Fields used for "CDO.Configuration", I had to play around to find the ones that my webhost seemed to care about. For instance, I have commented out cdoSendUsingPort and replaced it with a 2 (the actual value of cdoSendUsingPort). Most people online seem to be recommending putting the address of your SMTP server for the "smtpserver" setting, but I found that web.com only worked with "localhost".



Function SendEmail(Subject,Body,EmailTo,EmailFrom)
' SendEmail(Subject,Body,EmailTo,EmailFrom)
' 2/10/2009 JMJ: Uses CDOSYS method of sending email
'

Set cdoMessage = CreateObject("CDO.Message")
Set cdoConfig = CreateObject("CDO.Configuration")

Set Flds = cdoConfig.Fields

With Flds
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'cdoSendUsingPort
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Update
End With

With cdoMessage
Set .Configuration = cdoConfig
.To = EmailTo
.From = EmailFrom
.Subject = Subject
.TextBody = Body
.Send
End With

Set cdoMessage = Nothing
Set cdoConfig = Nothing
Set Flds = Nothing

SendEmail = true

End Function 'SendEmail()


Coincidentally, there are a couple more solutions out there. One is to copy a couple dll’s onto the new server to provide support for legacy ASP scripts; another is to just send emails using the database. I’ve provided some links below that were helpful to me.

Tips for Classic ASP developers on IIS7

IIS7 - Classic ASP Forum

How to send e-mail with CDO

ASP Sending e-mail with CDOSYS