reverse engineering things that predecessors left without any documentation and throwing them out the window because devops
Menu
menu

This howto describes how to relay mail (such as system alerts) to email services such as gmail. First part describes doing so using sSMTP which only supports relaying local system mail and the second part shows how to do this using Postfix which is a fully featured MTA. Postfix might be an overkill in most cases but hey, it might have features that you may find useful!

This howto is tailored to FreeBSD systems but the main configuration will work on other operating systems.

sSMTP

Start off by installing sSMTP through ports:

Once installed, create a /usr/local/etc/ssmtp/ssmtp.conf config file with the following contents:

For AuthUser, put down your gmail username or your full email for Google Apps account that you want to forward the mail to.

Next up, change the mailwrapper config to point to sSMTP by editing /etc/mailer/mailer.conf. Mailwrapper is a FreeBSD utility that lets you change sendmail into any other MTA. It was built and designed for this specific purpose as many system utilities were originally written to tie into Sendmail. Mailwrapper is installed by default on FreeBSD systems but if yours doesn’t have it, download the system sources and compile it:

You may also leave /etc/mailer/mailer.conf as default as is, and just change the /usr/sbin/sendmail into a symlink that points to /usr/local/sbin/ssmtp:

Test mail flow by using mailx:

You should see mail get processed in /var/log/maillog and come to your gmail account.

Postfix

Second option is to use Postfix. Being a fully featured MTA, it may be an overkill but we’ll go over it in case you want to send mail from other machines on your network (which was my usecase). Of course, I don’t have to remind you about securing your MTA on your network. Open relaying used to be a thing but with advent of spamming, it’s been disabled on most MTAs. We will be enabling this functionality, but we will only enable it to listen on a local interface and to accept connections from local networks. You will need to ensure that port 25 is disabled/blocked on your local firewall. Most ISPs block port 25 anyway.

Start off by installing Postfix:

Make sure to select cyrus-sasl auth module during the config dialog.

Once installed, created /usr/local/etc/postfix/main.cf file and change the following options:

Change the /usr/sbin/sendmail symlink to point to Mailwrapper. This also makes sure that mail will not go out via sSMTP.

Start Postfix:

or:

Test mail flow via mail command or telnet:

You should see mail get processed in /var/log/maillog and come to your gmail account.

You will also be able to send mail from other systems on your local LAN. Simply point your MUA/mail client to your server or use telnet to test connectivity.

At this point you should be done configuring a mail relay to send email to outside services. Above examples used gmail but any other service should work.

Leave a reply