Add ssmtp mail
Mail is very useful for sending notifications and text messages about issues on a Raspberry Pi.
Most email clients will block all email from an unknown domain, which is why gmail or some other known domain must be used to forward a Raspberry Pi's email.
The Raspberry Pi needs a Mail Transfer Agent, like sendmail, exim4, or postfix.
Required Parts:
Raspberry Pi running raspbian with ssh enabled
Step 1. Open terminal windows and login
Step 2. Always update and upgrade
Step 3. Install SSMTP and mail utilities
Run the commands:
$ sudo apt-get install ssmtp mailutils -y
Step 4. Edit the SSMTP configuration file
Edit the config file using:
$ sudo nano /etc/ssmtp/ssmtp.conf
as follows:
root=♣your-gmail-account♣@gmail.com
mailhub=smtp.gmail.com:587
hostname=♣your-hostname♣
AuthUser=♣your-gmail-account♣@gmail.com
AuthPass=♣your-gmail-password♣
UseSTARTTLS=YES
Step 5. Edit the SSMTP aliases file
Edit the config file:
$ sudo nano /etc/ssmtp/revaliases
Create one line for each user in your system that will be able to send emails. For example:
root:♣your-gmail-account♣@gmail.com:smtp.gmail.com:587
Step 6. Set the permissions
Set permissions of the SSMTP configuration file:
$ sudo chmod og+x /etc/ssmtp/ssmtp.conf
Step 7. Set up Gmail to Forward Filtered Mail to Smart Phone
Keep your ♣ID♣
Step 8. Try it
Get the script:
$ wget https://raw.githubusercontent.com/dumbo25/send-text-message/main/emailTry.py
Edit the file and put in your values in the angle brackets:
$ nano emailTry.py
Run the script using
$ python emailTry.py
Note:
gmail receives the email and forwards to AT&T immediately. However, delivery of the message to my phone through AT&T (txt.att.net or mms.att.net) is very slow. A text message takes 22 minutes to go through AT&T and be delivered to my phone. I get the same delays whether the email is sent from the Raspberry Pi try.py script or from my gmail account. Using a filter in gmail, seems to eliminate the delay.
I checked my iPhone settings and nothing is blocking or slowing delivery.