I will like to take you through how to send mail using crontab. Kindly follow the steps in every folder.
-
Update your sudo
sudo apt update
-
Install ssmtp
sudo apt install ssmtp
-
Edit sssmtp folder - there are two folders that we will edit in this part. The first one is ssmtp.conf
nano /etc/ssmtp/ssmtp.conf
Inside this folder, we will edit the following; root=[email protected] mailhub=smtp.mail.gmail.com:587 FromLineOverride=YES UseSTARTTLS=YES AuthUser=[email protected] AuthPass=getThisPasswordFromYourGmail(GoogleHowToGetIt) TLS_CA_File=-/cert.pem -
Edit the second ssmtp file
nano /etc/ssmtp/revaliases
Paste this in the folder yourPCUsername:[email protected]:smtp.mail.gmail.com:587 -
Create your shell script file
-
Get the path of the shell script file. Edit the crontab
crontab -e
Set the crontab to anytime you want the mail to deliver. Example 0 * * * * will deliver the mail at 12am of everyday. -
Ensure your local machine(laptop, desktop, or any machine) is connected to the internet. This will let the mail deliver inside your email.
-
Another way to send to mail is to use
mail -s "mail topic" folder [email protected]