Amazon recently announced that they have added an SMTP interface to their Simple Email Service. Now, this is pretty cool. This means that we can now use our very own cfmail tag in ColdFusion to send emails using Amazon’s SMTP/SES service. The Simple Email Service allows you to send emails – although you need to have verified senders on the account and the account should be in production mode to be able to send emails out to anyone. Previously, the only way to send emails was either using Amazon’s SDK or using their REST API (which I wrote a ColdFusion wrapper for as well) but now, you can use the native cfmail tag to send out emails – which I think is pretty cool.

Once you have followed the steps described in the post above ie created your SMTP username/password, you can use the code below to send out emails :-

[cf]

<cfset ses_smtp = {} />
<cfset ses_smtp.port = "465" />
<cfset ses_smtp.server = "email-smtp.us-east-1.amazonaws.com" />
<cfset ses_smtp.username = "your_ses_smtp_username" />
<cfset ses_smtp.password = "your_ses_smtp_password" />

<cfmail
to="recipient@domain.com"
from="sender@domain.com"
subject="Using SES SMTP"
type="HTML"
username="#ses_smtp.username#"
password="#ses_smtp.password#"
usetls="true"
usessl="true"
port="#ses_smtp.port#"
server="#ses_smtp.server#">
This email is being sent using Amazon’s SMTP support for SES.
</cfmail>

[/cf]

The above code works on my installation of Railo (have not tried in Adobe CF but can’t see why it will not work)

Tagged with:  

9 Responses to Sending Email with the new SMTP Support for Amazon SES

  1. John Gag says:

    Awesome. Cant wait to try it out

  2. Henry Ho says:

    I wonder if IP from Amazon SES are more likely blocked by spam filter since almost anyone can send email from them, including spammers?

  3. Pradeep says:

    Woah ! this is big! thanks for the post, i missed this.

  4. Nando says:

    A quick note to say I have it working on CF9. Thanks for the post. I found out here that I needed to set usessl=”true” (or Amazon rejects the email).

  5. Jeromy says:

    Can the SES SMTP server be configured into the Railo (4.03) server using the Railo Administrator? I just tried, but it timed out…

    • Anuj Gakhar says:

      Hi Jeromy, I have not tried this myself yet but conceptually this should work. Did you enable tls in the settings?

      • Jeromy says:

        Yes, I enabled tls and ssl and used the same server/username/password settings as the ones that *work* on the cfmail tag. I wonder if this might be an authorized sender type of thing–Railo might be trying to send a test message via tester@railo.org or some such, but that address is not an authorized sender on my (or anyone’s) account.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

© 2011 Anuj Gakhar
%d bloggers like this: