Having made some changes to how my email is handled recently I wanted to tidy things up by having my FreeBSD systems submit mail via my mail provider's authenticated SMTP submission service.

Googling for how to do this turned up a lot of advice, much of it dated and often more complicated than is currently required, so I thought I'd document where I got to for the benefit of others trying to do this.

I'm assuming this is being done on a system where sendmail has already been configured generally. See the FreeBSD handbook if this isn't the case.

Firstly, the Sendmail shipped with FreeBSD 13 doesn't include the SASL features required to do authentication. The easist way to fix this is to install a more complete version from pkg using pkg install sendmail.

Once this is done, installing the supplied mailer.conf file will tell the system to use this version of sendmail.


cd /usr/local/etc/mail
cp mailer.conf.sendmail mailer.conf

To tell sendmail to use a smarthost, and to authenticate to it requires a couple of changes.

Firstly in /etc/mail/${HOST}.mc, add


define(`SMART_HOST', `smtp.example.com')
define(`RELAY_MAILER_ARGS', `TCP $h 587')dnl
FEATURE(`authinfo', `hash -o /etc/mail/authinfo')dnl

Then create /etc/mail/authinfo containing


AuthInfo:smtp.example.com "U:me@example.com" "I:me@example.com" "P:passw0rd" "M:LOGIN"

For my provider the U: (username) and I: (identity) values are the same, for others they may be different, e.g. to send from a different mailbox to the one being used to authenticate.

Build the authinfo database, and install the modified sendmail configuration:


cd /etc/mail
makemap hash authinfo < authinfo
make all
make install
service sendmail restart