Self-hosted: Email with Custom Domain

This page will demonstrate how to self host an email server with little to no cost. The goal by the end is for us to have a usable email server and inbox that uses a custom domain. It is assumed that the reader is operating from a residential network.

Preface

To host our own email, we need two abilities: sending emails and reading emails.

To send emails, we use the Simple Mail Transport Protocol (SMTP). This protocol acts like the post office in regular paper mail, where once we drop off an envelope, it is delivered from one post office to another until the destination. Similarly, once we drop off an email on an SMTP server, it relays that email to other SMTP servers to deliver it digitally.

To read emails, we use the Internet Message Access Protocol (IMAP). This protocol is kind of like one’s literal mailbox. It is a server that one can connect to at any time to read and manage their email. There is also the POP3 protocol to read emails, but this one is much more limited in what it can do, and mostly serves as a legacy fallback.

The terms MTA and MDA are also used to signify SMTP and IMAP servers. The two popular programs that provide these two functionalities are postfix and dovecot, which handle sending and reading emails, respectively.

Unfortunately, most residential internet service providers block the standard port for sending and receiving emails (port 25). This means that even if one correctly sets up their email server at home, the mail traffic cannot leave their home.

In addition, residential IPs are generally not static, and static IPs are required to edit one’s reverse DNS entry. This last part is crucial, because most major email providers, such as Gmail and iCloud, reject email from IPs without a reverse DNS entry.

Mail Relays

To work around not being able to receive emails on port 25, one option would be to relay incoming mail through a VPS. Unfortunately, VPS usually cost money to rent each month. Since we are trying to keep costs down, subscribing monthly to access a server is out the window.

Luckily, there is a little known service called GhettoSMTP that does this for free. Note that this service is run by a hobbyist and is not backed by a corporation. That isn’t to say that they will vanish out of existence one day (quite the opposite, in fact a Reddit post from over ten years ago mentions GhettoSMTP), but just know that the scope of the service will be most likely limited.

Another potential hazard is that the owner can technically read your emails, but at that point so can all the other SMTP servers between the sender’s server and your server read your emails. Email is not that secure anyway.

Personally for me, these are not dealbreaking issues, since I won’t be using this for my primary email anyways. I will assume the same for the reader as well. To set this service up, one may follow the detailed list of steps on their website.

Now that we can receive emails, we can move on to tackling sending emails. The playbook here is similar: because we can’t send emails ourselves, we can employ a relay to send emails for us. In contrast to relaying incoming mail, there are many relays services for outgoing mail, both paid or free. Personally, I chose SMTP2GO for its large quantity of emails in the free plan, but one can choose any of the other excellent services.

Now all that’s left to do is to hook up our postfix and dovecot setup to both of these services. Here is a diagram illustrating what we would like to set up:

Sending emails

OOuurrPmoasitlfixMTAROeucripSiMeTnPt2'GsOMRaeillabyox····

Receiving emails

SIennbdoexr'smailOur·Do·ve·co·t·MD·A··GOhuerttPooSsMtTfPi'xsMMTTAA