Linux Tips : SSMTP

I’ve now been using Manjaro Linux since the start of 2020

So far so good, I’m getting used to the way it works. Linux quirks that can be a real pain to learn or get used to. Coming from Windows after using it for over 30 years, for about 90% of the time I’m pleased with it.

Unlike Windows it’s harder to use, to modify or create files, folders in certain places etc can be a real pain, because of Linux’s security, I suppose it’s a good thing, but wrapping you head around how to modify a dopey file or to add a line can be more than just a pain in the ass.

In a these posts, I’m trying to write down things that I found really hard to do or learn, or very time consuming to do, hoping that maybe of some use to someone.

This tip is how to get Cron to send an email when the job has been completed (in my case a backup evry hour from 9h – 22h, sadly as like many of Linux’s programs this is far from easy.

Being in Manjaro, I first has to install ssmtp, this the easy part…

Once installed you will find a folder at /etc/ssmtp/
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.

In the conf file once open 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
Paste this
hostname=user-manjaro
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

I’ll try and explain what needs to be modified in the above lines

ssmtp.conf
user-manjaro (open a terminal, type hostname
mymail@gmail.com replace with your gmail address
AuthPass=123456 need if you use gmail with 2FA, you have to create a special password under gmail security’s settings to let ssmtp / Linux send yurself mails (https://support.google.com/accounts/answer/185833?hl=en)

So once these details have been sent you can modify the second file Revaliases
Paste this
root:mymail@gmail.com:smtp.gmail.com:587
localusername:mymail@gmail.com:smtp.gmail.com:587

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

See https://minty95.wordpress.com/2020/04/27/linux-tips-cron/

Now when your cron job runs, you will receive a mail, sadly the subject of the cron command line , it’s 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

Feel free to leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s