Send and Receive Emails with Custom Domain – Powered (and Overkilled) by Amazon SES

Send and Receive Emails with Custom Domain – Powered (and Overkilled) by Amazon SES

The Motive

There are a lot of things that you can do after having a custom domain. One of them, for example, is to send and receive emails with your custom domain.

One use case is to use website-specific email addresses when signing up on different websites. For example, I used SOME_SERVICE_NAME@mydomain.com as my account name for a service, and later received a few unrelated junk emails at that address. Then I know who sold or leaked my information.

Apparently, an alternative way is using "+" in your user name (e.g. johndoe+foo@hotmail.com where the emails actually go to johndoe@hotmail.com). There might be a chance, though, that it will fail some extra-strict validations that disallow the use of the plus sign – even though it is legit.

All that said, the purpose of this post is to set up email address with custom domain, so that it can be used for sending and practically receiving emails, in the very same fashion of a personal mailbox.

Solution overview

Despite the fact that Amazon SES is mostly designed for programmatic email sending at scale, it is still the first idea that came to my mind – nothing strange about it since I’m an existing AWS user. So keep in mind, it’s probably not the perfect use case – in fact, it is overkill for my use case.

On sending end, I use Thunderbird and configure its SMTP setting to use SES, and then I can send emails from any username with my domain.

On receiving end, Amazon SES doesn’t come with POP or IMAP servers. This means that it is not designed to be work as a personal inbox. However, I can set up receipt rules to save received emails to S3, and invoke a Lambda function to forward to a designated inbox.

Prerequisite

Sending Emails

Amazon SES provides 2 ways for sending emails: through its API, or through SMTP servers. Since my use case is to send emails from an email client, as opposed to in a programmatic way, I’m setting up for SMTP servers.

The reason why Thunderbird is chosen as email client is that I can change whatever username as sender address (i.e. any_arbitrary_name@mydomain.com). Below is a guide to configure Thunderbird to send email through SES:

https://aryehsilver.co.uk/configuring-thunderbird-to-send-through-amazon-ses/

A few more notes:

  • Make sure to note or download the SMTP credentials upon generation.
  • To set sender address, you can use Thunderbird’s “manage identities” functionality, or simply modify Email Address of default identity, before selecting the send from address.

Receiving Emails

As is mentioned, Amazon SES doesn’t come with IMAP or POP servers. Therefore with SES, I can’t technically receive emails as if it’s on my personal mailbox. However, I can still get these emails in personal mailbox that I designated. The trick here is to configure SES to forward emails to my inbox.

Here is an AWS blog that explains it. Basically this process involves a few more entities: S3 and Lambda. The core logic here is the receipt rule that defines 2 steps:

  1. Upon receiving of an email targeting my domain, save the email to a S3 bucket;
  2. Then trigger a Lambda function that:
    • fetch the email content from S3, and
    • send to my personal inbox as specified

References

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.