FreeBSD is shipped with sendmail as the default MTA, which is configured to local delivery on a vanilla installation. Therefore many people don’t even recognize one of FreeBSDs great features for system administrators: FreeBSD sends system status emails through periodic(8)…
…that reveal interesting information such as disk status (even with ZFS integration), installed packages with known vulnerabilities or SSH login attempts. And this is even jail-aware so the status mails for example contain information about insecure packages in your jails as well.
But configuring your MTA properly can also be useful in other situations. So so might wanna send email from a blog running on your local webserver.
SSMTP offers a great solution for this by redirecting all local email to a external SMTP server and delivering it to a specified email address. Additionally it’s easy to configure.
First we need to configure SSMTP to become the default MTA used for delivering your mails. First we need to disable sendmail.
SSMTP as the default MTA
The MTA is enabled by default. Let’s disable it first.
Now we can install SSMTP using pkg or the ports collection. I go with pkg:
pkg install ssmtp
The new MTA gets a separate user. Additionally you should set proper permissions to it’s configuration directory.
pw useradd ssmtp -g nogroup -h - -s /sbin/nologin -d /nonexistent -c "sSMTP pseudo-user"
chown ssmtp:wheel .
chmod 4750 .
chown ssmtp:nogroup /usr/local/sbin/ssmtp
chmod 4555 /usr/local/sbin/ssmtp
FreeBSD provides a configuration file that allows you to configure your preferred MTA called
Replace the first two lines to match the lines in this example:
Now we can use the configuration file example called
cp ssmtp.conf.sample ssmtp.conf
chown ssmtp:wheel . ssmtp.conf
chmod 640 ssmtp.conf
ssmtp.conf looks like this, which should also work for you. My server uses SMTP with STARTTLS on Port 587:
mailhub=**mailserver ip address**:587
Hostname=**name of your maildomain, e.g. example.com**
RewriteDomain=**same as Hostname**
revaliases file contains the mapping from the local user to target email address. I only configured the root
user as I only want the periodic status mails which are delivered to root by default.
root:**email address**:**mailserver ip address**:587
Now you can send a email to any address to check if relay works. I send the contents of my
rc.conf file here:
sendmail firstname.lastname@example.org < /etc/rc.conf