Linux – SSMTP – sending emails from a Linux system

SSMTP – sending emails from a Linux system : I’ve been using Manjaro Linux since the beginning of 2020 ( 2021 I have switched to Arch Linux but I’m still using the same SSMTP set-up)

Linux unlike Windows can be harder to use. To modify or create files or folders in certain places can be a real pain, because of it’ security. It’s a good thing, but wrapping you head around how to modify a dopey file that needs root access can be a real pain in the ass.

In a these posts, I’m trying to write down things that I found hard or complicated to do or learn, and sometimes very time consuming. So hopefully they maybe of some use to you.

This tip is to get my Cron backups to send an email when the job has been completed. Sadly as with many Linux’s programs this is far from easy.

First I had to install ssmtp, that was the easy part… (update 2021 SSMTP is no longer updated by Arch linux, but it can still be found and downloaded using Yay and works fine) I tried a later version such as openssmtp but buggered if I could get it to work, so stick to the ssmtp version, updated or not it works

Once installed you will find a folder at /etc/ssmtp/ (Reboot, otherwise ssmtp won’t work…..)
Inside will be two files, ssmtp.conf & revaliases. As usual these have only root permissions and so you need to modify them as root and not as user.

Image of my ssmtp folder in /etc/
Image of my ssmtp folder in /etc/

In the conf file once opened you just need to paste the following under the line # The full hostname (for info when a line has a # in front of it, this means that it’s a commented line not a command line)

ssmtp.conf

ssmtp.conf (change the red details for yours)
Paste this
hostname=user-manjaro (‘user-manjaro’ this is my user/hostname name, in my Arch Linux setup it’s now xxxx-arch for instance)
TLS_CA_File=/etc/ssl/certs/ca-certificates.crt
root=mymail@gmail.com
mailhub=smtp.gmail.com:587
rewriteDomain=
hostname=user-manjaro
UseSTARTTLS=YES
AuthUser=mymail@gmail.com
AuthPass=123456
FromLineOverride=YES
AuthMethod=LOGIN


AuthPass=123456 needed if you use gmail with 2FA, you have to create a special password under gmail security’s settings to let ssmtp / Linux send yourself mails (https://support.google.com/accounts/answer/185833?hl=en)

Once these details have been done you can modify the second file Revaliases

Revaliases

Paste these two lines in the revaliases file, again you need root access to modify this file and modify just the red details for your own
root:mymail@gmail.com:smtp.gmail.com:587
localusername:mymail@gmail.com:smtp.gmail.com:587

With all this done you can now use SSMTP for sending emails from your Linux system

Update end 2021 I also ssmtp on my Arch Arm running on a raspberry Pi4 that I play with, except that I came across an error message ‘Cannot open mail:25’ this took time to suss out. It’s due to rights on the ssmtp folder and the revaliases and conf files. Just Chmod the files to 640 and low and behold the mail:25 error go away (sudo chmod 640 /etc/ssmtp/revaliases)

PS : To check on Chmod valeurs.

stat -c %a /etc/ssmtp/ssmtp.conf or stat -c %a /etc/ssmtp/revaliases

The results are :
Where: /etc/ssmtp/revaliases
Chmod: 640

The ssmtp folder (/etc/ssmtp) when I first installed a year ago, had a chmod valeur of 755 this now seem to be have changed with an update and is now 770. 770 means its locked but mails are still sent as long as the two files in it are 640 but 770 means it’s a pain to open it. If need be change it back to 755 (it’s my computer, nobody uses it so security is not a great concern for me, saves using root or sudo su to get into it)

Back to your cron files

Once this has been done, you can modify your cron file and instead of
MAILTO=””
MAILTO=mymail@gmail.com

See https://bit.ly/2UXUDI8

Now when your cron job runs, you will receive a mail. The subject of the cron subject line is long and a mess : but it’s better than nothing

Email subject line : Cron <root@usermanjaro> root rsync -avhW /home/trevor/Documents/* /run/media/trevor/BackUp_1/Copy_trevor_home_documents