Solved

ASP CDO with Amazon SES

Posted on 2014-11-22
4
722 Views
Last Modified: 2014-12-09
I am trying to move a script that uses CDO over from using SMTP.com mail relay to using Amazon SES service.

The code was working previously with SMTP, but the configuration of SMTP.com was set to allow all requests from the web server IP that the code is sitting on.  With Amazon SES this isnt possible and you have to authenticate.  SES doesnt allow anything but SSL/TLS connections, hence why i think its failing.

The code is:

Set Mail = CreateObject("CDO.Message")

    Mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing")= 2
    Mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")= "email-smtp.us-east-1.amazonaws.com"
    Mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")= 465
    Mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1
    Mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
    Mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
    Mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") ="un"
    Mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") ="pw"

    'update the configuration options
    Mail.Configuration.Fields.Update
    
	Mail.From = "info@xxx.com"
	Mail.To = strSendTo
	Mail.Bcc = Bcc
	Mail.Cc = Cc
	Mail.Subject = strSubject 
		IF BodyFormat = 1 THEN
			Mail.TextBody = strMessage
		ELSEIF BodyFormat = 0 THEN
			Mail.HtmlBody = strMessage
		END IF
	Mail.Send
Set Mail = Nothing

Open in new window


If i use the code above, it fails with:


error '80040211'
/pages/processing/process_let_us_contact.asp, line 36

Any idea how i can get ASP classic to work with AWS SES?

I have tried switching to port 25 and the problem is the same.

Thanks,
Carl
0
Comment
Question by:net-workx
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 53

Accepted Solution

by:
Scott Fell,  EE MVE earned 500 total points
ID: 40459589
What you have looks good.  Are you 100% sure you have AWS SES set up correctly? Paid etc?

I have used sendgrid for this type of thing and  now mandrill.  Mandrill is free for the first 11,000 monthly emails and I would suggest using this or sendgrid for better deliverability.

This is what I use for mandrill
theHtml = "<table>full email html</table>"

' Set stuff up here
Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory. 
Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network). 
Const cdoAnonymous = 0 'Do not authenticate
Const cdoBasic = 1 'basic (clear-text) authentication
Const cdoNTLM = 2 'NTLM
'SMTP userinfo
smtpUser="me@mydomain.com"
smtpPass="mypassword"

unsubscribeHTML ="<div>This email newsletter is only sent to our students and friends.   If you no longer wish to receive these emails, please click the remove me link.  <a href=""*|UNSUB:http://mydomain.com/unsubscribe/|*"">Click here to unsubscribe.</a></div>"


theHtml=theHtml&unsubscribeHTML

Set objMessage = CreateObject("CDO.Message") 
objMessage.Subject = theSubject 
objMessage.From = "News <me@mydomain.com>"
objMessage.To = ""&(rsEmailList.Fields.Item("FirstName").Value)&" "&(rsEmailList.Fields.Item("LastName").Value)&" <"&rsEmailList.Fields.Item("Email").Value&">"'Rcpt
objMessage.HTMLBody =  theHtml' runs sub EmailBody

'==This section provides the configuration information for the remote SMTP server.
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") =  "smtp.mandrillapp.com" 
'Type of authentication, NONE, Basic (Base64 encoded), NTLM
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
'Your UserID on the SMTP server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = smtpUser
'Your password on the SMTP server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = smtpPass
'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465 
'Use SSL for the connection (False or True)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = true
'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objMessage.Configuration.Fields.Update

'==End remote SMTP server configuration section==

objMessage.Send

Open in new window


It is important to note that I have also set up dkim and spf records.  And that may be something you are missing in AWS.
0
 
LVL 53

Expert Comment

by:Scott Fell, EE MVE
ID: 40459592
I also  use this site as my reference http://www.paulsadowski.com/wsh/cdo.htm

Another options is to use the aws api http://docs.aws.amazon.com/ses/latest/APIReference/API_SendEmail.html

You can simply use xmlhttppost to send the data
POST / HTTP/1.1
Date: Thu, 18 Aug 2011 22:25:27 GMT
Host: email.us-east-1.amazonaws.com
Content-Type: application/x-www-form-urlencoded
X-Amzn-Authorization: AWS3 AWSAccessKeyId=AKIAIOSFODNN7EXAMPLE,
 Signature=yXx/wM1bESLuDErJ6HpZg9JK8Gjau7EUe4FWEfmhodo=,
 Algorithm=HmacSHA256, SignedHeaders=Date;Host
Content-Length: 230

AWSAccessKeyId=AKIAIOSFODNN7EXAMPLE
&Action=SendEmail
&Destination.ToAddresses.member.1=allan%40example.com
&Message.Body.Text.Data=body
&Message.Subject.Data=Example&Source=user%40example.com
&Timestamp=2011-08-18T22%3A25%3A27.000Z

Open in new window

0
 
LVL 53

Expert Comment

by:Scott Fell, EE MVE
ID: 40459608
One last option that I have resorted to is to use an sdk that already exits like php.  Then set up a php page to do the work for you as your own web service where you can post data to via classic asp xmlhttpost.  It can be a lot easier than trying to program the long way in classic asp.

https://github.com/aws/aws-sdk-php
http://docs.aws.amazon.com/aws-sdk-php/latest/class-Aws.Ses.SesClient.html#_sendEmail
$result = $client->sendEmail(array(
    // Source is required
    'Source' => 'string',
    // Destination is required
    'Destination' => array(
        'ToAddresses' => array('string', ... ),
        'CcAddresses' => array('string', ... ),
        'BccAddresses' => array('string', ... ),
    ),
    // Message is required
    'Message' => array(
        // Subject is required
        'Subject' => array(
            // Data is required
            'Data' => 'string',
            'Charset' => 'string',
        ),
        // Body is required
        'Body' => array(
            'Text' => array(
                // Data is required
                'Data' => 'string',
                'Charset' => 'string',
            ),
            'Html' => array(
                // Data is required
                'Data' => 'string',
                'Charset' => 'string',
            ),
        ),
    ),
    'ReplyToAddresses' => array('string', ... ),
    'ReturnPath' => 'string',
));

Open in new window

0
 

Author Closing Comment

by:net-workx
ID: 40489997
Sorry for the delay - accepted this cannot be done natively and switched to mandrill.

thanks
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Html Table looping 4 41
ASP Classic - JavaScript - Get value from form in iFrame and pass to main page. 2 39
ASP and Extracting XML 7 44
SQL to JSON 14 64
There was an incident about the POP3 issue for the double read receipts and delivery receipts in Exchange 2013.  There was huge research been done and found solution for the duplicate mails. Especially when the user gets  duplicate mails.
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Steps to create a PostgreSQL RDS instance in the Amazon cloud. We will cover some of the default settings and show how to connect to the instance once it is up and running.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question