Sending email in the cloud
Having run a couple of startup companies in the cloud on Amazon Web Services, the issue of sending email has cropped up a number of times.
The problems
Amazon doesn't allow you to set reverse DNS lookup entries for your mail server and a large number of mail servers will not accept mail from a server that doesn't have this. This is a spam prevention feature to try and cut down on mail being relayed through insecure mail servers.
The other blocking issue you will come across is blacklisting. Because of the nature of cloud systems it is likely that someone else has had your IP address in the past. If the person wasn't entirely honest then they will probably have been blacklisted at some point. Here is an example error message you will receive if you try and mail from a blacklisted host:
553 Mail from xx.xxx.xxx.xxx not allowed - 5.7.1 [BL21] Connections not accepted from IP addresses on Spamhaus PBL; see http://postmaster.yahoo.com/550-bl21.html [550]
or
550 DY-001 Mail rejected by Windows Live Hotmail for policy reasons. We generally do not accept email from dynamic IP's as they are not typically used to deliver unauthenticated SMTP e-mail to an Internet mail server...
The solutions
So, what can you do about it? The simple answer is do not send mail from the cloud, instead relay your mail through a server hosted somewhere else.
The first option is to send email through GMail. This works fine for small volumes of email but as your web application becomes more succesful you will quickly start hitting the volume limits imposed by Google and will start seeing entries like this in your mail log:
550 5.4.5 Daily sending quota exceeded.
The best long-term solution is to run your own mail server hosted outside of the cloud. I recommend slicehost as a provider, you can have a mail server up and running from as little as $20/month and this will allow you to send masses of email. This might sound a bit ominous if you haven't set one up before but they have a great tutorial on setting up a mail server.
Dodging the spam folder
Once you have your mail server up and running you should set an SPF record for your domain. SPF records are TXT DNS records that you create to announce that your new mail server is allowed to send mail for your domain. Lets say you have just finished setting up your mail host as mail.example.com then you need to create a TXT entry for example.com with the following contents (including the quotes!):
"v=spf1 include:mail.example.com -all"
You should now be sending mail happily from the cloud and with a bit of luck your recipients will receive the mail in their inboxes.
