Sending email using Amazon SES with Classic ASP

John Avis by | March 21, 2017 | Classic ASP

I recently needed to change a client's website to send emails using Amazon SES and encountered a few issues.
I recently needed to change a client's website to send emails using Amazon SES and encountered a few issues.

The client's code was using jMail COM component but I couldn't make this work, most likely because Amazon SES requires use of TLS and I could not find how to enable this in jMail, if it supports it at all.

So the solution was to change to CDOSYS, but this required some experimentation before it would work.

Some of the errors I received along the way were:

• The server rejected the sender address
• The server response was: 530 Authentication required
• 530 Must issue a STARTTLS command first

To use CDOSYS with Amazon SES you must specify a remote server, authenticate using basic authentication, use port 25, and use SSL (not TLS as I attempted).

This sample code worked for me. You will of course need to include your own Amazon SES SMTP login details, server name, and verified sender address.

Dim objMessage
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Your subject"
objMessage.From = "test@exampledomain.com"
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "email-smtp.us-west-2.amazonaws.com" 'Change if using a different Amazon SES server
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "Your Amazon SES SMTP username, usually starts with AKI..."
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "Your Amazon SES SMTP password"
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
objMessage.Configuration.Fields.Update
objMessage.TextBody = "This is a test email"
objMessage.To = "success@simulator.amazonses.com"

On Error Resume Next
objMessage.Send

If Err.Number = 0 Then
Response.Write("OK")
Else
Response.Write("FAIL: " + Err.Description)
End If

Related Posts

Classic ASP

Classic ASP class constructors with parameters

by John Avis | June 8, 2016

Although probably no one cares about Classic ASP, except those who still need to support it, I was refreshing my memory today on how to use classes in Classic ASP and found a couple of options for simulating constructors with parameters.


Classic ASP

Classic ASP cookie with no name hacking attack causing error 80004005

by John Avis | July 31, 2015

As of July 2015, many of my Classic ASP websites have started logging strange errors, either 80004005 or not reporting any error code at all.


Classic ASP

Classic ASP functions for database queries and SQL injection protection

by John Avis | July 28, 2014

If writing database queries in SQL in Classic ASP for SQL Server, rather than using ADO or parameterised queries, you can use these functions to correctly format your data and protect against SQL injection.

Comments

There are no comments yet. Be the first to leave a comment!

Leave a Comment
Tags
ASP.NET Html Forms ASP.NET MVC ASP.NET Web Forms ASP.NET Web Pages Bootstrap C# Classic ASP Cool Websites Databases eBay and PayPal Electrical Repairs General Hardware HTML/CSS Jquery/Javascript Media Center Mobile Phones Responsive Web Design SEO and Social Networking Web Design Web Development Web Security web+db Website Hosting Windows XP

About me

...mostly about web development and programming, with a little bit of anything else related to the Internet, computers and technology.

Subscribe

Get the latest posts delivered to your inbox.