I realised that I could have spent the last twenty years putting all my tech knowledge online. Well, I didn't, but as they say, the best time to plant trees is 20 years ago, the second best time is now. So here's all the random programming stuff I've come across that might be helpful. Note: this isn't really questions and answers - more just answers from me!

CDONTS, CDOSYS, IIS 6.0, IIS 7.0 and headaches...

0 votes
We moved from an old IIS 6.0 server setup with Classic ASP code sending bulk newsletter emails using CDONTS, to a new Windows 2008 R2 server in the cloud with IIS 7.5. We also moved to using a 3rd party SMTP service - sendgrid. We had problems...

Okay, now the fun starts. We originally had CDONTS working with some other 64 bit components. No, really, we have proof. But after some replication and reconfigration of instances everything stopped working together. We have no idea why, and never managed to get them all playing nicely again.

So, CDONTS is old, eh, so we should upgrade to CDOSYS, we told ourselves. So we re-wrote some newsletter sending code to using CDOSYS instead of CDONTS, and dutifully filled in the sendgrid configuration as per instructions, for your ref, here's how to do it for sendgrid:

Dim iMsg, iConf, Flds
Const cdoSendUsingPickup = 1
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
Dim sch : sch = "http://schemas.microsoft.com/cdo/configuration/"
With Flds
.Item(sch & "sendusing") = 2
.Item(sch & "smtpserver") = "smtp.sendgrid.net"
.Item(sch & "smtpserverport") =465
.Item(sch & "smtpconnectiontimeout") = 10
.item(sch & "smtpauthenticate") = 1 'basic auth
.item(sch & "smtpusessl") = True
.item(sch & "sendusername") = "myusername"
.item(sch & "sendpassword") = "mypassword"
End With
With iMsg
Set .Configuration = iConf
End With

And whilst we're here, here's how to add a sendgrid category header for CDOSYS:

iMsg.fields("urn:schemas:mailheader:X-SMTPAPI") = "{""category"":""myCategory""}"

And, for the hell of it, if you were still using CDONTS, here's how you'd add a sendgrid category field, it's a JSON formatted field:

Mail.Value("X-SMTPAPI") = "{""category"":""myCategory""}"

So, back to the tale. Our bulk newsletter suddenly went from taking about 13 minutes to send to taking about 2 hours! And this was a small newsletter. The time our main newsletter would now take was greater than 8 hours - not an option.

So, thinking caps on.

Hang on. Why are we specifying the SMTP gateway explictly for every email we send? Sendgrid have instructions for configuring IIS to use their SMTP gateway by default - just go into IIS and check the mail settings. They even have a page about it: http://docs.sendgrid.com/documentation/get-started/integrate/examples/microsoft-iis-7-5/ (for the record, you can configure IIS 6.0 fine as well, we got this working - you need to specify a fully qualifed domain name, and then the smtp.sendgrid.net as the smarthost, with don't try primary first option).

So, maybe CDOSYS would be faster if we don't specify all the config, but send it, vanilla-like. And yes, if send without all the config (just delete all the config bit of the code above), just a plain old CDOSYS email, then it just gets sent to the mail queue. It seems like if you do specify SMTP info explictly, then ASP hangs around and waits to check it for each email - almost a second an email!

A quick test sending 20 emails:

CDOSYS with STMP config: Execution time: 15.5039 seconds
CDOSYS without SMTP config: Execution time: 0.3867 seconds

Which is quite a difference eh?

Anyway, I hope this helps someone, somewhere - we spent a lot of time on this!
asked Mar 8 in Classic ASP by Ralpharama (280 points)

Please log in or register to answer this question.