Email with EC2

A quick search of the web reveals that Amazon’s EC2 is perhaps not a great choice for a host when it comes to sending emails. Workarounds exist - using a 3rd party forwarding service, for example (see Paul Dowman’s blog for a good discussion) - but what do you do if you have to send emails from your EC2 instances? What can you do to give your email the best chance of getting delivered?

Here are some ideas that should help things a little:

  • Make use of Elastic IPs: assign a static IP address to your instance.
  • Check that your IP address is not blacklisted (a quick Google search reveals several tools).
  • Assign a hostname to the server that matches an actual DNS record that’s pointing at it. The default EC2 hostnames have embedded IP addresses that spam-prevention systems may be wary of. Actually, it’s probably worth adding the hostname to /etc/hosts too (use the private IP for this), and on Fedora at least, you probably want to set the hostname in /etc/sysconfig/network so that it persists across reboots.
  • Make sure you are sending emails with a From: address matching the domain in question, or any domain that actually has records pointing at the machine if you are hosting multiple.
  • Create an SPF record for your domain that authorizes your EC2 instance to send email.
  • If necessary, be sure to tell your MTA to trust the applications you are using to send email - e.g. mongrel and apache. With sendmail you can do this by adding the users that these applications run as to the file /etc/mail/trusted-users and restarting the service. Not doing this can result in the MTA leaving warnings in your mail headers.
  • Finally, use some decent content in the email - the less your email looks like spam, the more chance there is of it getting past (say) a Bayesian filter.

Please respond if you have any feedback or further tips when it comes to emailing from EC2.

Tags:

Leave a Reply