Configuring Windows 2012 SMTP for CDONTS (Classic ASP)

I spent about three hours chasing down these errors

Three Different Errors in my IIS Log

When using Port:

80040213 The_transport_failed_to_connect_to_the_server.

8004020f [no text, just this code]

When using Pickup Directory”

80040222 The_pickup_directory_path_is_required_and_was_not_specified

So when reading other blogs, they often tell you to change from Pickup Directory to Port or vise versa.

Context

This code below came from an old Windows 2003 machine running IIS.  I’m migrating to an Amazon EC2 instance running Windows 2012.  My application is a classic ASP application that I have never rewritten.  I remember having similar difficulties back then, decided Microsoft’s SMTP was too complicated, tried some others, and ended up running MailEnable.

CODE

I have a VBScript Class in a separate file that can be shared by any program that needs to send an email.  That’s the first block of code below.  The second block of is uses the class to try to send the email.  It was bombing on the line that said “cdomsg.Send”.

<%

Class Mail
public emailTo
public emailFrom
public emailSubject
public emailBody

public function send

Set cdomsg = CreateObject(“CDO.Message”)

Set iConf = Server.CreateObject(“CDO.Configuration”)

Set Flds = iConf.Fields

‘ Neal changed 12/12/2007 – was getting error:
‘ Arguments are of the wrong type, are out of acceptable range,
‘ or are in conflict with one another
‘ Actually – had to add the MetaData clause at the top
Flds.Item(cdoSendUsingMethod) = 1 ‘ 1=pickup 2=port
‘ The value of 2 might require a user/pass, but you must specify port & server
‘Flds.Item(“http://schemas.microsoft.com/cdo/configuration/sendusername”) = “MyUser”
‘Flds.Item(“http://schemas.microsoft.com/cdo/configuration/sendusername”) = “MyPass”
Flds.Item(“http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory”) = “c:\inetpub\mailroot\pickup”

‘Flds.Item(cdoSMTPServer) = “127.0.0.1”
Flds.Item(cdoSMTPServer) = “localhost”
Flds.Item(cdoSMTPServerPort) = 25
Flds.Item(cdoSMTPconnectiontimeout) = 10
Flds.Update

Set cdomsg.Configuration = iConf

cdomsg.from = emailFrom
cdomsg.to = emailTo
cdomsg.subject = emailSubject
cdomsg.textbody = emailBody
cdomsg.Send
Set cdomsg = Nothing ‘ not allowed to reuse it for another message
end function

End Class
%>


&lt;%
&lt;!--METADATA TYPE="typelib" UUID="CD000000-8B95-11D1-82DB-00C04FB1625D" NAME="CDO for Windows 2000 Library"--&gt;
Response.Write "Attempt to send mail "
Set objMail = new Mail
objMail.emailFrom = "me@mydomain.com"
objMail.emailTo = "you@mydomain.com"
objMail.emailSubject = "TestMail.asp from mydomain.com server"
objMail.emailBody = "Body of email, this is a test"
objMail.Send  ' was getting error on this line when attempting to send email
Set objMail = Nothing ' not allowed to reuse it for another message
Response.Write "Mail sent"
%&gt;
<!-- #include file="ClassMail.asp" -->

The Steps I Took To Solve the Problem

Obviously, I had to get IIS installed.  One possible issue is that I installed it, but I didn’t configure it.

1. I basically followed these steps to Setup and Configure SMTP.   I did not setup their firewall rules, because I’m running IIS and SMTP on the very same server. I did one thing not on their list. From the “Security” tab of the SMTP Virtual Server Properties, I added the local user account tied to the Application Pool.

2. I did add a local user account, assigned that account to my IIS Application Pool, restart the app pool.  I gave that account access to my IIS files directory, and to the pickup directory.  At this point, I’m not sure that was needed or not.

3. I never got to work using 2=port, only 1=pickup.

Flds.Item(cdoSendUsingMethod) = 1 ‘ 1=pickup 2=port

If you specify 1 for pickup, then I now am pretty certain you must also specify the pickup directory name:

Flds.Item(“http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory”) = “c:\inetpub\mailroot\pickup”

I’m guessing that CDONTs writes to that directory, and that write access is required for the user running the App Pool.

Not having the “pickup directory” specified was causing this error:  80040222 The_pickup_directory_path_is_required_and_was_not_specified

Followup: Later I plan to try one of my other IIS websites, to see if they work “as is”, or if they need a local account and security granted as well.

Uncategorized  

Leave a Reply