Monday, October 26, 2009

Sending mail from EC2 Servers

Sending mail from EC2 servers, is for the most part the same as sending email from any other dedicated server. Setup Postfix and then use the "sendmail" provided by postfix. In your web applications just use "localhost" as your smtp server. This works, except that Amazon EC2 IPs are now blacklisted by Spamhaus, so corporations that fight spam based on Spamhaus info will block all your messages.

That's exactly what happened to us. I'm not the only one having email sending issues with EC2, there are several articles about the Spamhaus, EC2 issue.


Use an SMTP server external to EC2 for handling mail sending. I first tried to use gmail, but gmail alters the sender address, so that all messages appear to come from gmail, not quite what I needed.

  1. Add a relayhost entry to postfix (for me this was in /etc/postfix/
    relayhost =
  2. On the host that will be acting as a relay (in this example also in the /etc/postfix/ file), I added the reserved ip address for my EC2 instance to the mynetworks list
    mynetworks = #where this represents the ip of my ec2 server
That's it.
After running /etc/init.d/postfix restart on both servers, no more blacklisting issues.

The problem with this is that I end up needing to have a server outside of the cloud, which brings a single point of failure and works against the scalability of cloud based solutions.

Hmmm, wonder if I could run my smtp server in Google App Engine, somehow.

No comments:

Sign up for my upcoming Plone 5 Book & Video tutorials

plone 5 for newbies book and videos