GMail as mail relay for your Linux home server

Since my Fedora Post-installation Configurations article, some things have changed in Fedora 20. For example, for security and economy reasons, Sendmail does not get installed anymore by default. Here are the steps to make your Linux home computer be able to send system e-mails as alerts or from things that run on cron. All commands should be run as user root. This is certified to work on Fedora 21.

  1. Enable less secure authentication on Google dashboard.
  2. Install and configure stuff:
    yum install sendmail-cf patch wget cyrus-sasl-plain;
    wget -O /tmp/sendmail.mc.patch http://avi.alkalay.net/articlefiles/2011/01/sendmail.mc.patch;
    cd /etc/mail;
    patch < /tmp/sendmail.mc.patch;
    chmod go-rw authinfo;
  3. Edit the authinfo file and put your Gmail login and password.
  4. Configure the system so your mail address receives all mail for root. Do this editing /etc/aliases and make sure it has this line, generally at the very end:
    # Person who should get root's mail
    root:           YOUR-EMAIL-ADDRESS@domain.com
  5. Build new Sendmail configuration, update edited mail aliases database:
    cd /etc/mail;
    make;    # to regenerate the config files based on our changes
    newaliases;
  6. Create a key and a test certificate for Sendmail so Gmail will allow us to connect:
    cd /etc/pki/tls/certs;
    make -f /usr/share/doc/openssl/Makefile.certificate sendmail.pem;
  7. Enable Sendmail on boot and start it:
    systemctl enable sendmail;
    systemctl restart sendmail;

Now the system is able to send you warnings, cron outputs etc by e-mail. To test it, you can do this as any user:

mail -a /some/file/to/be/attached -s "Subject line" recipient@somedomain.com <<EOF
Body of the message goes here...
EOF

The message will be sent with an attachment.

One thought on “GMail as mail relay for your Linux home server”

Leave a Reply to Fedora Post-installation Configurations Cancel reply

Your email address will not be published. Required fields are marked *