Using Raspbian and Ubunntu 16.04 LTS so need a generic Linux solution.
Requirement is simple:
I need a way to send one-line email messages from the command line.
I have set up a gmail account just for this particular Rpi3, with the address of rpi3abc@gmail.com – with no 2FA
So now I need to be able to send one-line mail messages from anywhere (including cron) without user intervention.
I also would like it to be able to send text files; basically, anything from stdin
.
Best Answer
The simplest answer to sending one-line messages via gmail is to use ssmtp
Install it with the following commands:
Edit
/etc/ssmtp/ssmtp.conf
to look like this:Send a one-liner like so:
or
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:
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 theFROM:
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.