Self-hosted Email Servers

(Title Illustration)

I wanted to set up a professional email address using my domain for a while now. While I probably won’t use it very often, it just looks professional especially on websites and resumes. Since I didn’t wish to pay Apple or Google monthly fees, I decided to dabble in the wonderful world of self-hosting email.

Initially, I was expecting it to be smooth-sailing by installing a couple of programs, setting up some configuration, and perhaps some automation scripts. However, once I’ve discovered the world of IP reputation and deliverability issues, it became clear that some effort was needed to host my own email.

This blog post will detail how my current email system works.

Background

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

To send emails, we can 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 can use the Internet Message Access Protocol (IMAP). This protocol is kind of like your literal mailbox. It is a server that you can connect to at any time to read and manage your 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 two popular programs that provide these two functionalities are postfix and dovecot, which handle sending and reading emails, respectively. You might also hear the terms MTA and MDA used, but they mean similar things.

Initial plan

My first thought was that email hosting would be similar to website hosting. So, my initial plan was that I would host everything and manage everything from sending, to receiving, and to storage. I had just gotten acquainted with email protocols and the infrastruction, and begun configuring the various pieces of software to work together in harmony. Then I stumbled across this Reddit post, which made me doubt if everything would be easy.

Here’s an edited excerpt of it:

How can you tell if you should self-host an email server? Ask these questions.

  1. Am I willing to do some work to make this work? If not, stop.
  2. Is this my first venture into Linux or Docker or self hosting or any kind of new technology? If it is, stop. Host something else first, get your feet under you.
  3. Will my ISP allow incoming access to ports 25, 465, 587, 993 to my IP? If not, stop.
  4. Do I have a static IP which will also let me edit my rDNS entry? If not, Stop. Your ability to prove you aren’t spam relies a lot on rDNS. Check my domain’s MX records (which is my username) to see what I mean. I have a static IP with business class Verizon FiOS. Anything less, and I can’t touch that entry. I also pay more for internet because of this.
  5. Will I do the due diligence of receiving and looking at the SPF and DMARC reports you can get about your email? If not, stop. These are daily (or weekly) emails from other domains about any issues they saw. You need to pay attention to these and if you don’t, you do so at your own peril.

I was feeling pretty good when I read the first two questions: I was willing to spend some time to set up the mail server, and I had some experience with Linux previously. This confidence was completely gone, however, when I read the next two questions.

For starters, I found out after some basic testing that like most providers, my ISP blocked port 25. This means that I am unable to connect with other SMTP servers to send or receive emails, since all SMTP connections happen on port 25. In addition, I was not on a business class internet plan with my ISP, which meant that I had a dynamic IP and had no control over my reverse DNS entry.

Thus, the former constraint removed my ability to send and receive emails by blocking all connections with other mail servers; the latter guaranteed that even if I was able to send emails, they would most likely be rejected by major email providers like Gmail and iCloud. Needless to say, a mail server without the ability to send or receive email isn’t particularly useful.

GhettoSMTP

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 I’m trying to keep costs down by not having more subscriptions1, that’s out the window.

Luckily, there is a little known service called GhettoSMTP that does this for free. Now, I do have to put a disclaimer here that when I say it is little known, I mean it. When I asked the owner of GhettoSMTP whether the service has a privacy policy, I got the following response:

No privacy policy to speak of — I’m just a free hobbyist service so you should probably treat it accordingly. Just something fun to play with and use.

Sent from my iPad

So, before you decide to use GhettoSMTP for your next best project based on this blog post, know that the service really isn’t backed by some large and commercial company. That isn’t to say that they will vanish out of existence one day (actually quite the opposite; I found a Reddit post over ten years ago mentioning 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.

For me, however, these are not dealbreaking issues since this won’t be my primary email anyways. I won’t go over the details of setting up the service here, mainly because that would bloat the length of the article too long, but you can go take a look at GhettoSMTP’s website if you’re interested. The website has a detailed list of steps to follow and a list of FAQs.

SMTP2GO

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. There are many relays, paid or free, out there that one can use. Personally, I chose SMTP2GO for its large quantity of emails in the free plan.

The setup process is straightforward, and the control panel is easy to use. You don’t even need to hook up a card to begin using their free tier, which was a nice surprise.

Now all that’s left to do is to hook up our postfix and dovecot setup to both of these services. There are a lot of tutorials online for this already, so I’ll skip over that part here. For reference, my final set up looked something like the following2:

Sending emails

MMyyPmoasitlfixMTAReMcyipSiMeTnPt2'GsOMRaeillabyox····

Receiving emails

SIennbdoexr'smailMy·Do·ve·co·t·MD·A··GhMeyttPooSsMtTfPi'xsMMTTAA

Epilogue

Going back to that one redditor’s list of questions to ask oneself before self-hosting email, they were not kidding when they said that work was necessary to host one’s own email. I know I made it look mostly straightforward in this post, but in reality, I was testing out different methods and workarounds for sending email on and off for at least six months before landing on this solution.

Part of the hassle is due to popular mail providers’ strict spam detection, but those are probably necessary in order to combat actual spam. Thus, self-hosting email is more about working around these strict spam detection than simply configuring programs. Still, with some work, it is possible to assemble a setup that works for personal use.

Footnotes


  1. At this point, subscribing to Gmail to use their plans that allow custom domains would probably be more practical and convenient than subscribing to a VPS. ↩︎

  2. I was today years old when I learned that you can make these diagrams natively in Hugo. ↩︎



0

Have a comment or a question about this post? Reply by email!