Exercises in email self-hosting (2) Minimal - Receiving

Simple email exercise

We will start with a very simple email receiving server exercise.

Assuming you have a VPS and a spare domain name to play with. Let's say your main domain name is : testdomain.live We'll keep it very simple for now and for this test email part we'll add no MX record but just an A record. (If email server software cannot find a MX record it will default to the A record.) So, if your your website on your VPS has for example the ip address 104.9.9.9 then also add an A record for sub-domain mailtest.testdomain.live with the ip address 104.9.9.9 This DNS change might take some time. Make sure to check and see whether it works fine for your home computer with an ip lookup.


For this exercise I assume that we use Ubuntu Bionic Beaver (LTS, 18.04). Log in to your VPS via ssh. Make sure all software is upgraded : sudo apt update && sudo apt -y upgrade

Install postfix and mutt : sudo apt install postfix mutt

Choose "No configuration" for Postfix when asked.

add a new user called : testuser

sudo adduser testuser

Configure Postfix : sudo nano /etc/postfix/main.cf

Put these lines in the file (Adjust to your real test domain), and save and exit.

myorigin=mailtest.testdomain.live

mydestination = localhost, mailtest.testdomain.live

mynetworks = 127.0.0.0/8

inet_interfaces = all

inet_protocols = ipv4

smtpd_recipient_restrictions = permit_mynetworks, reject_unauth_destination

Run the command : sudo /usr/bin/newaliases (This is needed, otherwise Postfix will bail out about a missing file. Later on we will look at aliases) And then restart Postfix : sudo /etc/init.d/postfix restart

Now, after the DNS change has propagated, send an email from your home computer email client to testuser@mailtest.testdomain.live

Check the log files on your VPS with : sudo tail -f /var/log/mail.log

When the email has arrived, do the following on your VPS, preferably as "testuser" : mutt -f /var/mail/testuser Agree to add the Mail folder that mutt asks about. If all went fine you can see your first test email.

Inside mutt press "h" to see the headers

Press x to exit mutt.

If you succeeded : Congratulations ! :) You finished the simple receiving email exercise. Next part would be to send an email out. More about that in the next article in the series.

Disclaimer : Use at your own risk. I am not responsible for mistakes being made. Creating an open relay by mistake and getting into spam abuse problems is something to take care about.

Make sure you have your ssh logins secure. Highly recommended to use ssh keys, and then disable plain text password logins. Beware, don't lock yourself out. Here's a community howto how you can do that : https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys--2