Send emails via command line

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
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 and turn on Less secure app access.

Send me an email:
echo "Hi, this is an email" | mail -s "Test Message"

★ㄥinuメ★ TᎥƤ乙

View all 42 tips
or follow the