In the projects I envision for the future, I’ll be using my Raspberry Pi (RPi) as a gateway/server/controller for several other devices. There is likely to be a need to generate status reports/messages and mail them out. It could be as simple as a notification that the deck lights have been turned-on. I don’t need a full fledged mail client on the RPi to receive mail or manage a mailbox, just a command line utility to send email. Also, I would like to send short text messages via (SMS) to my cell phone. Linux does have a nice solution for this.
You do need an established email account with some email provider. I want to keep my personal email and my RPi’s email separate so I setup a special email account on gmail. This will be used only by my Raspberry Pi’s (or other intelligent devices). There exist some open SMTP relay mail servers (mail servers that will not require a login nor a password) but many open mail relays have become unpopular and closed due to their exploitation by spammers and worms.
I installed SendEmail on my RPi via this command:
sudo apt-get install sendemail
When I ran sendEmail the first time, it complained about some missing libraries. I installed the missing libraries and this cleared the error. Clearly, the sendEmail package needs some work since this dependency should have been taken care of by
I ran it again using this command:
sendEmail -f pi@RedRPi -t email@example.com -u "Test Email from RedRPi" -m "My test message." -s smtp.gmail.com:587 -o tls=yes -xu my_user_name -xp my_password
With this, sendEmail threw an error message:
invalid SSL_version specified at /usr/share/perl5/IO/Socket/SSL.pm line 332
I did a web search and found that this is a reported bug within sendEmail (bummer), but I also found a simple patch for the problem (lucky break). I applied the fix, executed the command again, and succeeded in sending the email.
One of the key parameter used here is the SMTP mail relay specified in “
-s smtp.gmail.com:587“. In this case, Gmail uses port 587 for relay email. The default port to use is 25 but not all email servers use this port.
Another key parameter is “
-o tls=yes“. This specifies that the Transport Layer Security (TLS) protocol will be used to provide communication security over the Internet. This is important since your including a plain-text password in the command.
Another messaging mechanism that I plan to use is Short Message Service (SMS). To do this, you can use a SMS gateway which will transform an email into an SMS message. The down side is that there isn’t a single gateway but one for each of the cellular carries.
Here is an example for AT&T cell phones:
sendEmail -f pi@RedRPi -t firstname.lastname@example.org -u "Test Email from RedRPi" -m "My test message." -s smtp.gmail.com:587 -o tls=yes -xu my_user_name -xp my_password