Tuesday, January 25, 2011

Amazon Simple Email Service on Windows - How To

Today Amazon announced AWS Simple Email Service (SES) beta.  SES is a great addition to Amazon Web Services, with it an organization can send marketing, transactional, subscription or system notification messages without have to manage their own messaging infrastructure.  And just like all other AWS services it's pay-as-you-go - even free in some instances.

Soon as I received the announcement from Amazon I immediately set out to give it a try.  Since I normally use Windows that's what I used for this.  I ran into a couple of minor problems but was easily able to resolve them and now I'm sending email through SES like a mad man. . .

Summary - Quick Steps
If you're anxious to get started and don't want any fluff here you go.  For everyone else read below.
  • Sign-up for SES
  • Install Perl
    • Install XML-LibXML via Perl Package Manager (instructions below)
  • Download AWS SES scripts
  • Setup "credentials" file (see below for details)
  • Get verified: ses-verify-email-address.pl -k creds.txt -v test@powercram.com
  • Send email: ses-send-email.pl -k creds.txt -s "Test One" -f test@powercram.com test@powercram.com
Sign-up for SES.  If you already have an AWS account you're one step closer, if not you'll have to start there.

SES uses Perl scripts, therefore you must have Perl installed on your Windows machine.  I installed ActivePerl Community Edition.  Soon as that was done I ran the first SES script to get an email address verified but ran into my first problem - c:\perl\bin didn't get added to my path by the installation (for some reason it added c:\perl\site\bin) so I had to do that manually (if you don't know how to do this you probably shouldn't be here anyway. . . )

Amazon Simple Email Service Scripts
Download the SES scripts and save to a useful location - I used d:\aws\ses.  This download includes the following SES scripts:
  • ses-get-stats.pl - retrieves statistics about Amazon SES account usage
  • ses-send-email.pl - send email using Amazon SES
  • ses-verify-email-addresses.pl - verify email addresses to be used with Amazon SES
Next problem - when I ran ses-verify-email-address.pl --help I received the message: "Can't locate XML/LibXML.pm in @INC (@INC contains: C:/Perl/site/lib C:/Perl/lib.) at D:\AWS\SES\ses-verify-email-address.pl line 26.  BEGIN failed--compilation aborted at D:\AWS\SES\ses-verify-email-address.pl line 26."

After tooling around the web for a few minutes I realized I needed to manually install XML-LibXML.  This was easily done by opening the Perl Package Manager off the Start menu.  In there:
  • Click the "View All Packages" button or press Ctrl+1
  • Type libxml in the search box
  • Right-click on XML-LibXML and select Install . . .
  • Click File, Run Marked Actions or press Ctrl+Enter
Now when you run ses-verify-email-address.pl --help from the command line you can actually see the help for this command.

Credentials File for SES Commands
All of the SES scripts or commands require authentication to AWS, which makes sense.  You can save your credentials (both AWSAccessKeyId and AWSSecretKey) to a file, creds.txt and pass that to each script with the -k <filename> command.

Example credentials file:

Verify Email Address for SES
In order to send any email you must add & verify at least one email address to which you have access.  The verification is a two-step process.  First run the command: ses-verify-email-address.pl -k creds.txt -v test@powercram.com.  Amazon will send an email to that address with a link to click to finalize verification.

NOTE: Until you are granted production access to Amazon Simple Email Service you can only send to verified addresses. Click to Request for Production Access to Simple Email Service.  They say it may take up to 24 hours, but my access request was granted in about 30 minutes - now I can send to any address!

View List of Verified SES Addresses
By running the command ses-verify-email-address.pl -k creds.txt -l you are supposed to be able to view a list of verified addresses, however when I run this nothing is returned.  I did discover though that using the --verbose switch, ses-verify-email-address.pl -k creds.txt -l --verbose, I am able to view a list of verified addresses:

<listverifiedemailaddressesresponse xmlns="http://ses.amazonaws.com/doc/2010-12</p><p>01/">

Send Email With SES
Finally we are ready to send email using the command ses-send-email.pl -k creds.txt -s "Test One" -f test@powercram.com test@powercram.com.  Press Enter then you can type the body of your message.  When that's done press CTRL+Z, then Enter.  It will hesitate for a second or two while your credentials, etc. are verified and the message is queued.  Finally, check your email.

Amazon Simple Email Service looks to be a very useful tool and is a great addition to Amazon Web Services.  In just a few minutes you can be sending email through SES, and it can be adapted for myriad purposes.  Get started today and start emailing (useful messages - NO SPAM or other crap!).

Additional Info
See Also


  1. Thanks buddy, you saved my time!

  2. I'm very thankful for this post. I was having the same issues of nothing showing up for -l flag and I was using Ctrl-D instead of Ctrl-Z and was wondering why emails weren't sending. THANKS!

  3. My perl scripts are showing all the time like I am not entering the correct arguments.
    C:\Users\Zammy\Desktop\Dispenr\bin>ses-verify-email-address.pl -k creds.txt -v evgeni.i.petrov@gmail.c0m
    Begining of parse_argsBegining of validate_opts
    ses-verify-email-address.pl [--help] [-e URL] [-k FILE] [--verbose] -v
    EMAIL | -l | -d EMAIL


  4. Just a note. I used Strawberry Perl and it did not work out!

  5. Great Guide!

    I installed XML Lib and I still can't get the Perl Scripts work.


    root@MailWorks:~# /aws/ses/ses-get-stats.pl --help
    Can't locate SES.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.10.1 /usr/local/share/perl/5.10.1 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10 /usr/local/lib/site_perl .) at /aws/ses/ses-get-stats.pl line 23.
    BEGIN failed--compilation aborted at /aws/ses/ses-get-stats.pl line 23.


  6. @Kevin W read the README file included in the ses package, it gives 3 solututions to the "Can't locate SES.pm in @INC" problem.

    export PERL5LIB=/opt/third-party/amazon/ses (use the appropriate path)

    use lib '/opt/third-party/amazon/ses'; (again use correct path and place this in the pl scripts before the use SES line)

    perl -I/opt/third-party/amazon/ses ./ses-send-email.pl (once again use correct path)

  7. Great post.
    you are really great.

  8. thanks a lot ! you saved my time!

  9. Man Great post! Thankful for people like you to post their experiences. Blogs have pretty much helped me out since I've been working on Amazon EC2.

  10. Hello. I tried to run the verify script and the cmd module just crashes. Any ideas on what's going on?

  11. I just spent hours on this, it seems the latest perl 5.14... doesn't have Switch.pm, you need to get an old version, 5.12... grrrr

  12. Thanks. I tried this on Windows Server 2008 m1.small EC2 instance and works great. Thanks so much. I have verified that it sends to both Yahoo and Hotmail no problems.

    Thanks for this useful post.