Gathering data and automatically sending email to your smartphone is simple with the tiny Linux machines BeagleBone or Raspberry Pi, with the help of a little program called sendEmail. It’s small, doesn’t take many computing resources and is easy to implement.
BeagleBone and Pi are perfect for many hobbyist/entrepreneur/Maker-type Internet of Things projects. They work great from the command line. Another cool feature is the ability to read and set inputs and outputs at the hardware pin level.
Suppose you have a magnetic reed switch that’s attached to your garage door and hooked up to one of the BeagleBone’s input pins. Moving the door changes the value on the I/O pin, which can be recorded in a text file for logging purposes. You could massively increase the functionality by sending a text message to your smartphone whenever the door goes up. Isn’t that something you’d want to know about, instantly, whether you’re asleep at 3 a.m. or away from home?
The task is a piece of cake with sendEmail, a simple command-line outbound SMTP client used to automatically send a note from the command line, a script or a cron job. The process is easy to set up and doesn’t require any other programs to work correctly. Obvious applications are physical security and fault monitoring, process completion ACKs or simple status messaging. Just think: push a couple of buttons on a box somewhere and you get an informational message on your smartphone.
Trivial examples? Sure. But don’t forget: when in doubt, use Linux to automate everything in sight.
Send a Message From the Command Line
Installing sendEmail on your small-footprint Linux machine couldn’t be easier: Just use apt-get.
rob@rob-notebook:~$ sudo apt-get install sendemail
A couple of extra libraries are also needed to keep your email password safe.
rob@rob-notebook:~$ sudo apt-get install libssl-devrob@rob-notebook:~$ sudo apt-get install libio-socket-ssl-perl
The basic form of the command is:
rob@rob-notebook:~$ sendEmail -f [from email address] -t [to email address] -u [mail topic] -m [message body] -s [smtp server:port] -xu [your smtp server user name] -xp [your smpt server password]
The mail topic and message body entries need to be in quotation marks. You should also have a working text-messaging account through your cellular carrier.
Here’s an example of the command I used for a message from my Xubuntu notebook. Use your own email information and password, naturally.
rob@rob-notebook:~$ sendEmail -f email@example.com -t firstname.lastname@example.org -u "test message 2" -m "this is another test" -s smtp.mynetwork.com:587 -xu email@example.com -xp mypassword
If your first message fails, confirm the to address and port number used by your SMTP server. I initially assumed that I was using a standard Internet service provider’s SMTP port. The default is usually 25; my particular ISP uses 587. Your router may also block outbound traffic on your specific port number. Adjust as needed.
Failed delivery attempts frequently return emails back to your account, so checking your inbox might give you clues as to why sendEmail isn’t working.
Sending to Multiple Addresses
More coolness can be had by sending messages to multiple email or cellphone addresses using the
-cc option. All you have to do is add it into your command line using a space between each address. Here’s an example:
rob@rob-notebook:~$ sendEmail -f firstname.lastname@example.org -t email@example.com -cc firstname.lastname@example.org email@example.com -u "test message 2" -m "this is another test" -s smtp.mynetwork.com:587 -xu firstname.lastname@example.org -xp mypassword
This might be applicable if several people are on call — such as ops people or systems admins. I’m sure you’ll see how the sendEmail command can be used to make your life easier.
Type of Messaging Gateway
Another thing you might want to investigate when sending messages to a smartphone is the type of messaging gateway used by the carrier. For example, with AT&T, if you send a message to email@example.com, the message received on the smartphone would be from a rather large number (the “sender”) that’s incremented for each message. This situation may not be optimal for your purposes, because each one will appear to be from a different sender. Your list of “sender” contacts will grow to an unmanageable length, especially if you’re automating a task that spits out text messages every few minutes. Effectively, sending to this address negates what you put in the command line for the
On the other hand, if you send a message to firstname.lastname@example.org, when it hits the smartphone it will be predictably from whatever is in the “-f” field. And, it doesn’t change with each succeeding message.
You can also put the sendEmail line in a shell script.
I opened a new file called “messageout” with VI and simply stuck the command on the first line. Next, I changed the message section to read the first command-line argument.
rob@rob-notebook:~$ sendEmail -f email@example.com -t firstname.lastname@example.org -u "test message 2" -m $1 -s smtp.mynetwork.com:587 -xu email@example.com -xp mypassword
Last, I changed the permission on the messageout file to make it executable.
rob@rob-notebook:~$ chmod +x messageout
Now, to execute the script and add the text message.
rob@rob-notebook:~$ ./messageout "This message is new"
The script will run and send your message to your phone.
Sending Input/Output Pin States
To send input/output pin states on the BeagleBone, just collect the data and shove it into a text file. Then insert the text into the messageout script as an argument. For an in-depth discussion on interfacing with the BeagleBone pins, take a look at this.
You can also integrate the messageout script into the cron facility. This lets you collect system data (from information on the BeagleBone) and then forward it to the smartphone at a certain time. Maybe you’d want to get an input reading every hour, but you can’t or don’t want to stay logged in to the BeagleBone remotely over SSH. A cron job running the messageout script and sending a short status message might be all you need.
I’ve outlined the basics of using the sendEmail program. Now it’s up to you to go out and take advantage of the magic of automation with Linux, a BeagleBone and sendEmail.