Send emails via command line

06-26-2021
Linux mail command.

You can use it to send emails via your GMail account. Since mail is a command line tool you can use it in scripts and it also works with crontab.
You have to install the ssmtp tool once and fill in a configuration file.
sudo apt install ssmtp

sudo nano /etc/ssmtp/ssmtp.conf

In /etc/ssmtp/ssmtp.conf you have to enter your e-mail details:
# The place where the mail goes. The actual machine name is required no
# MX records are consulted. Commonly mail hosts are named mail.domain.com
mailhub=smtp.gmail.com:587
UseTLS=YES
UseSTARTTLS=YES
AuthUser=youremailaddress@gmail.com
AuthPass=GMail password

Then you must set in your Google account (not in GMail) that you only want to send emails via password protection.
Go to https://myaccount.google.com/u/0/?hl=nl and turn on Less secure app access.

Send me an email:
echo "Hi, this is an email" | mail -s "Test Message" marcel@marcelv.net

★ㄥinuメ★ TᎥƤ乙

View all 42 tips
or follow the
RSS-feed.
 
×
×