Using ssmtp instead of sendmail

I had problems with my mails from my server got categorized as spam in GMail :-(

So I decided to use Google's smtp gateway for sending the mails ...

I run FreeBSD:

1[root@prism ~]# uname -a
2FreeBSD prism.local 11.0-RELEASE-p9 FreeBSD 11.0-RELEASE-p9 #0: Tue Apr 11 08:48:40 UTC 2017  amd64

First disable sendmail (insert this into /etc/rc.conf:


And ensure that sendmail is no longer running: killall sendmail

Now install (I use pkg) ssmtp:

1[root@prism ~]# pkg install ssmtp

And then to replace sendmail with ssmtp change your /etc/mail/mailer.conf to:

1sendmail	/usr/local/sbin/ssmtp
2send-mail	/usr/local/sbin/ssmtp
3mailq		/usr/local/sbin/ssmtp
4newaliases	/usr/local/sbin/ssmtp
5hoststat	/usr/bin/true
6purgestat	/usr/bin/true

To use Google's smtp, you need to:

  • Create an App-password for you GMail account
  • Modify /usr/local/etc/ssmtp/ssmtp.conf

Goto apppasswords to create an App-password for the server to use your account.

And insert/uncomment something like this into the /usr/local/etc/ssmtp/ssmtp.conf:

You should now be able to send mails from the commandline:

1mail -v -s \"test subject\"

I also created a .forward file in /root/ with the to-email where I wanted all my system mail to go.