How to setup a email address for a domain on Amazon EC2?

Solution 1:

Depending upon your requirements, you either

A) Use SNS

or

B) don't send email.

Sure, internal email will work fine, but just about everything you send should get rejected as spam unless you send from ec2-a-b-c-d.compute-1.amazonaws.com. To set up email you need matching reverse-IP mappings, not to mention SPF and DKIM. With EC2 you don't have access to the authoritative DNS sources for the IPs and therefore can't properly configure the network.

SNS isn't intended for sending mail to end users, but if you're after monitoring or workflow configuration, it'll fit your bill quite nicely.

Likely you'll want an external mailhost. I hear Rackspace has some nice options, but I've never used them myself.

Edited

I was unaware of the Amazon mail requests form: this provides another option that will let you send mail from EC2.

You'll first have to allocate and assign an Elastic IP to your mail server, since this removes the fluidity problem. Be sure to set up monitoring, since if your mail server goes down your Elastic IP will be left dangling and you have to pay per hour for unattached Elastic IPs.

Next, you'll need to set up a forward mapping to this IP from your domain: in BIND syntax for the zonefile "example.com.", that'd be

mail   IN  A  1.2.3.4

Depending upon your DNS settings (specifically, your RTTL) this may take some time to propagate. It's easiest just to wait a day, but you'll probably be safe whenever a nslookup mail.example.com returns 1.2.3.4.

You should also specify that mail to your server should be handled by mail.example.com, since the old public IP your EC2 instance had will be replaced by the new elastic IP.

Include the EIP in the form where requested, and mail.example.com as the reverse DNS.

(In BIND, the record would be entered as 4.3.2.1.in-addr.arpa. IN PTR mail.example.com.)

As the form states, it may take some time for whitelists to be updated.

Pitfalls:

EC2 hosts are not intended to be terribly stable. If you use this as a production service you should have two mail server hosts configured fully redundantly. If/when one fails, you should have the ability to automatically or at least quickly deploy a new server to replace it.

Solution 2:

These days, you may also be interested in:

Amazon Simple Email Service (Amazon SES)

http://aws.amazon.com/ses/

If you are an Amazon EC2 user, you can get started with Amazon SES for free. You can send 2,000 messages for free each day when you call Amazon SES from an Amazon EC2 instance directly or through AWS Elastic Beanstalk. Many applications are able to operate entirely within this free tier limit.