The simplest answer to sending one-line messages via gmail is to use ssmtp
Install it with the following commands:
sudo apt-get update
sudo apt-get install ssmtp
Edit /etc/ssmtp/ssmtp.conf
to look like this:
root=rpi3abc@gmail.com
mailhub=smtp.gmail.com:465
FromLineOverride=YES
AuthUser=rpi3abc@gmail.com
AuthPass=testing123
UseTLS=YES
Send a one-liner like so:
echo "Testing...1...2...3" | ssmtp myusername@gmail.com
or
printf "Subject: Test\n\nTesting...1...2...3" | ssmtp myusername@gmail.com
Then, true to *nix, you just get the prompt back in a few seconds.
Check your myusername@gmail.com account, and voila, it is there!
This also works well when sending a file, as so:
cat program.py | ssmtp myotherusername@yahoo.com
And the program will show up in the mailbox
If the file is a text file, it can have a first line that says Subject: xxxxxx
This can be used with various cron jobs can send me data with subject lines indicating the content.
This will work with anything that prepares a message that is piped into ssmtp via stdin.
For more details such as securing these files against other users and such, visit this article:
Send Email from Raspberry Pi Command Line
Be sure to also look down below to the answer posted by Rui
about locking down the FROM:
address that might be changed in formatted message files, if necessary.
Now if only I could figure out how to send SMS the same way.