Setup your own email server (MTA) on the cheap - part 2

Previously I’ve recorded how to build your own email server for your own domain. Now Gmail and Yahoo can be a little picky about what they’ll let you use to send mail. Typically they’ll require (and it’s a good idea to have):
  • Authentication 
  • Secure traffic on port 587 or 465 
  • A valid SSL certificate
Side note, if you haven’t heard of LetsEncrypt, do some research. There’s no excuse for running unsecured web servers when you can get SSL certificates for free.

Here’s how to update our existing configuration to enable these features:

    1. Install sasl so we can use authentication

    sudo apt-get install sasl2-bin

    2. Edit /etc/postfix/main.cf to enable authentication. At the bottom of the file, add this text:
    3. Create a new user to send as. The bold text is what you’ll need to enter:

sudo adduser mailuser1
Adding user `mailuser1' ...
Adding new group `mailuser1' (1004) ...
Adding new user `mailuser1' (1004) with group `mailuser1' ...
Creating home directory `/home/mailuser1' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:xxxxx
Retype new UNIX password:xxxxx
passwd: password updated successfully
Changing the user information for mailuser1
Enter the new value, or press ENTER for the default
        Full Name []: Mail User 1
        Room Number []:
        Work Phone []:
        Home Phone []:
        Other []:
Is the information correct? [Y/n] Y
 
    4. Setup the temp location for sasl:

sudo mkdir -p /var/spool/postfix/var/run/saslauthd

    5. Because we're using chroot you need to edit the file /etc/default/saslauthd. You need to change the line:
OPTIONS="-c -m /var/run/saslauthd"
to:
OPTIONS="-c -m /var/spool/postfix/var/run/saslauthd"
Some sites will use a symbolic link to point postfix at the /var/spool path but this is the technique documented in the config file.
    6. Add the sasl daemon account to the postfix group

    sudo adduser postfix sasl

    7. Setup a chroot override so sasl can interact with postfix

    sudo dpkg-statoverride --add root sasl 710 /var/spool/postfix/var/run/saslauthd

    8. Setup LetsEncrypt:

    sudo apt-get install letsencrypt

    9. Create your certificate:

    sudo letsencrypt certonly --standalone -d mail.mydomain.com
 
    10. Update the PostFix config to use the new certificate:

    sudo postconf -e 'smtpd_tls_cert_file = /etc/letsencrypt/live/mail.mydomain.com/fullchain.pem'    sudo postconf -e 'smtpd_tls_key_file = /etc/letsencrypt/live/mail.mydomain.com/privkey.pem'

    11. Make sure Lets Encrypt to log its activity:

    sudo chmod -R 744 /var/log/letsencrypt/

    12. Update PostFix to use port 587 and TLS. Edit the file /etc/postfix/master.cf and uncomment the line
    submission inet n - y - - smtpd

    13. Add these lines directly under the submission line in master.cf. This will remove the restrictions in main.cf for authenticated users. It should look like this:      14. Edit the file /etc/postfix/main.cf and add these lines:
    15. Refresh the postfix configuration:

    sudo systemctl restart postfix.service

And that’s it. You can now setup Gmail or Yahoo to send as your new account. Just give it the hostname of your server, port 587, and the credentials you setup in step 3.

Big thanks to these sources:

Comments

Popular posts from this blog

Sync iTunes with MythMusic

Using Homebridge and Broadlink RM Mini to automate

LetsEncrypt and AWS ELB Load Balancers