Running your mail server through EC2
(Spoiler: It. Gets. "Uhg"ly...)



It seemed like such a good idea at the time...

The proposition was simple enough. I'm a tech-savvy guy with an interest in computers, and I own a domain and (now) a static webpage. How do I get my email off of @gmail.com and push it into the proper domain space, @fullmeshnetworking.com? Turns out, there are a few solutions. Companies like Google and AWS will *happily* run your messaging service through their servers for a nominal fee. This is the avenue most people would go down, most people being rational humans who think that $60 a year for a company like Amazon to handle all your email traffic, spam control, encryption, accounts, server maintenance, and DNS entries isn't at all unreasonable (Amazon seriously does this for $60 per user per year. Seriously, if you want custom domain mail and don't feel like slogging through the rest of the article, go sign up for Simple Email Service (SES) from Amazon. They don't pay me to say that, it's just WELL worth the money)


That's absolute nonsense, Zac. You already have a perfectly good *FREE* EC2 server sitting in the cloud burning processing power on nothing--
Run your own email server! It'll be free and better!

                                                                                                              -The Voice in Zac's Head that sends him on a journey of self-loathing.


As Kanye West is Fond of Saying "Start it Up..."

Projected time for this projected was about 2 hours. The steps were simple enough. Spin up an EC2 Linux instance, set the security group for "mail" (with my own defined security rules), program the mail client that everyone on the message boards can't stop raving about "Postfix," assign the DNS entries for a mail server correctly through Amazon Route 53, and call it a day. That gives you email, right? So simple!

10. Hours. Later...

I'm going to go into expansive detail about what happened and why, but I'm also going to cut to the chase for those interested in getting to the point. After about 10 hours of work (and 3 or 4 instances later--one of which involved a mySQL database because there are *lunatics* writing tutorials on the internet), I did have a server that would relay and send mail as instructed. Basically. It was not user-friendly, feature rich, or probably what anyone imagines when they imagine owning a "mail server." It *does* send mail. It 100% does that. Unencrypted, plaintext mail, with some really sketchy headers, that won't pass even the most recursive of spam filter checks. So... you know, it's a free/open-source service that is as effective as the amount of time and energy you'll put into it. Take it for what it's worth. Personally, if my consulting business takes off, I'll give Amazon the $5/month to run my mail for me.

Here we have screenshot-goodness PROOF that I did in fact have a SERVER which sent MAIL hence MAILSERVER.
(don't ask about quality)


You Were So Excited, Zac! What Happened?!

You know, ever since I worked in an enterprise environment, I've had a bit of disdain for the guys in messaging. I mean.... the job seems SUPER simple. Babysit a mail server, and keep it from being broken. Thing is, the mail server seems to ALWAYS be broken. That's because mail servers, and mail service in general, is vastly VASTLY more complicated than we, as modern internet users, have been lead to believe.

Consider the following: You have a GMail account (the end-user standard if you don't want to be teased mercilessly (by me) for still being on hotmail). That account probably gets hammered with THOUSANDS of junk emails every day. The smtp server that processes that, probably deals with bad emails in the millions. Despite the fact that the first thing humans did after inventing email was pollute it with junk mail somehow faster than we filled the ocean with plastic, all the emails that are supposed to get to you (more or less) get to you. Even more amazing than that, all the emails you want to get other places, get other places. The sheer volume of insane traffic and traffic checks that ANY smtp server has to execute just to do basic mail functions is staggering for a small server hobbyist.

Imagine this but more graffiti, less box, and mail actually comes and goes


But that's enough pandering the the messaging services technicians I always looked down on. Email is crazy complicated, mostly because it's become a service to effectively differentiate between what's real mail and what's bad mail. Sending and receiving messages is easy, validating them is almost impossible. Since this has devolved a little bit from my narrative, here's the rough bullet points of the 10 hour project:

  1. I spin up an amazon EC2, ssh in, and install postfix. It sends an email successfully but will not receive any email. Hours of tinkering go by. My dog demands a walk. Frustrated, I scrap the EC2 instance and find a new tutorial.
  2. I basically repeat bullet one. It grows late. I fall asleep on my keyboard. I wake up to a dog who's irritated the light is still on.
  3. As my postfix servers continue to not work I grow increasingly frustrated at my inability to perform what I believe is a simple task. I take some VERY interesting advice from a tutorial I find online:


"Brah, just use Postfix with mySQL integration on UBUNTU. That's the only REASONABLE way to run your mail relay. Oh you'll need some extra very confusing packages like Dovecot and some others you can't pronounce, also you'll BUILD a mySQL database by hand..."

  1. I scrap everything and go back to brass tacks, coming to the conclusion that I'm fundamentally misunderstanding something important.
  2. I discover that I can monitor postfix logs with"tail -f /var/log/maillog"
  3. I log into my latest (replica of my first) postfix server and discover that it's successfully exchanging mail like the good server that I know it is, only to have that mail silently obliterated by the smtp servers it hands mail off to because... headers, and reverse DNS checks, and SPAM filters....




So as it turns out, my 2 hour estimate for the inital mail server wasn't all that far off the mark. My first mail server... did everything it was supposed to do. I just wasn't checking the maillog tail to watch all the action behind the scene. So what are the key takeaways?

  • Amazon Linux is actually surprisingly easy to use if you have any familiarity with Linux at all. Just be ready to use a yum installer and tweak your context a little. There's plenty of command help available online.
  • Postfix is actually*surprisingly* easy to install and program if you just want to know how a mail relay works. Most of the optomiszation is handled by /etc/postfix/main.cf and if you wanna go nuts you can go over to /etc/postfix/master.cf
  • People on the internet really love the vi text editor. I don't know why. I nano everything. Other than providing line counts, I find vi horribly clunky and hard to use.
  • You should never try to run your own mail server.
  • Seriously, just don't do it.
  • It's nooooot worth your life, dude!
  • Just pay a professional to provide you enterprise class mail unless your organization is big enough to have a messaging department!
  • I don't have a comments section because I don't run a social media page, but feel free to email or call if you have any thoughts on this post!