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 root@amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC amd64
First disable sendmail
(insert this into /etc/rc.conf
:
1sendmail_enable="NO"
2sendmail_submit_enable="NO"
3sendmail_outbound_enable="NO"
4sendmail_msp_queue_enable="NO"
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
:
1mailhub=smtp.gmail.com:587
2AuthUser=yourmail@gmail.com
3AuthPass=yournewapppassword
4rewriteDomain=yourdomain.dk
5FromLineOverride=YES
6UseSTARTTLS=YES
You should now be able to send mails from the commandline:
1mail -v -s \"test subject\" yourmail@something.com
I also created a .forward
file in /root/
with the to-email where I wanted all my system mail to go.