OPS345

Email Server: SMTP and Postfix

Eric Brauer

Introduction: Email

  • Ain’t Going Anywhere!
  • Like a lot of early Internet stuff, has evolved over time.
  • Used to be we’d read email by logging in to the MTA server and reading it from the command line.
  • Later on, other protocols for downloading email from MTA to your computer was developed.
  • These days, we might use POP3/IMAP with a client like Thunderbird or Outlook.
  • Or we might just use the browser to access email, like Gmail or… Outlook.

Understanding The Diagram

  • For this course, we are interested in what happens between the Yellow Boxes.
  • Communication between MTAs is going to required a DNS query, slightly different from HTTPS requests.
  • SMTP is still the protocol we use for the actual sending of mail.
  • POP3/IMAP is covered in a later lab.

SMTP

  • Old
  • Still good
  • Uses port 25
  • To set up an Email server that can handle SMTP, we will use Postfix.

Setting Up Your email Instance

  • You know these steps already. Just create a new instance, make sure it’s reachable, and set up an Elastic IP.
  • Let’s assume I’m going to send you an email from my Gmail account.
  • You’ll need two new DNS entries so that my email can find your server:
    • We need an MX entry that tells Gmail what URL is handling email that ends in @user.ops345.ca.
    • Then we need an A entry that tell Gmail what IP Address is associated with that URL.

Exercise Caution ⚠

The steps in the lab here will ask you to mount an EBS, then move the contents of /home to that EBS, and then replace your home with that EBS. It’s very easy to break your server here, you will have to create a new email instance!

  1. Look at what’s in your /home directory before moving files (including ownership and permission).
  2. Transfer the contents.
  3. Verify that the contents of /tmp/home match what was there before. Including the Public Key.
  4. Test fstab before rebooting.

Postfix

The DNS entries mean that now, my Gmail knows where to find your email server. It’s knocking on your door. Now we need just need to answer it.

Postfix is already installed on your instances, but by default only handles email on localhost (ie, students emailing each other on Matrix). Follow the steps in the lab to allow the server to handle any email incoming on port 25, with user.ops345.ca as the domain.

Use ss (it has replaced netstat) to check your work.

Quick Note About the Telnet Test

I’m not on Rogers, but it still didn’t work for me. You can probably skip this step.

Aliases

Basically, when emails get sent to user root, you want to redirect that to your username (because you are the admin, after all!). This should be a simple step.

Conclusion

If all goes according to plan, you should be able to send an email from any account you own, and you should be able to read your email logs to see it received by your SMTP server. If not:

  • Are you seeing any log activity when you expect an email to arrive? Is it going to the wrong user?
  • Use ss to verify that your SMTP port is open.
  • Use systemctl status to make sure that Postfix didn’t encounter an error.
  • Use dig to make sure that DNS entries are correct.