Products for USB Sensing and Control
Products for USB Sensing and Control

How To Send Email from an SBC

Sending Email and SMS Text messages from an SBC


by James

Introduction

For this project, we will set up a system to send email alerts via an SBC using the SSMTP program on linux. SSMTP is a send-only email program that benefits from a relatively small amount of setup, making it ideal for sending emails from a user program or script.

Hardware

Only a Phidget SBC is required for this project.

Software

Setting up SSMTP

To use SSMTP, first install it with the command

        sudo apt-get install ssmtp
            

Once installed, you'll need to configure SSMTP to send emails via an email server. Here we'll use a Gmail acount. To set this up, open /etc/ssmtp/ssmtp.conf, either using vi or the text editor on the SBC website.

For Gmail setup, use mailhub=smtp.gmail.com:587. For simplicity, you can leave the hostname field undefined so SSMTP will use the hostname of the SBC. We used the following settings for our setup:

            
        #
        # Config file for SSMTP sendmail
        #
        # The person who gets all mail for userids < 1000
        # Make this empty to disable rewriting.
        root=YOUR_EMAIL@gmail.com

        # The place where the mail goes. The actual machine name is required no 
        # MX records are consulted. Commonly mailhosts are named mail.domain.com
        mailhub=smtp.gmail.com:587

        # Where will the mail seem to come from?
        #rewriteDomain=

        # The full hostname
        #hostname=

        # Are users allowed to set their own From: address?
        # YES - Allow the user to specify their own From: address
        # NO - Use the system generated From: address
        FromLineOverride=YES

        UseSTARTTLS=YES
        AuthUser=YOUR_EMAIL@gmail.com
        AuthPass=YOUR_PASSWORD
        AuthMethod=LOGIN
            
            

Note that your password is stored in this file as plaintext, so appropriate precautions should be taken to keep the acount on the SBC secure.

The Gmail server has recently implemented new security features that will block applications it deems insecure. This includes simple applications like SSMTP. As a result, you will either have to allow less secure apps, or set an app password if you are using 2-Step-Verificaiton.

That's all the configuration needed for basic operation of SSMTP. It is now ready to use. To test that you have set up SSMTP correctly, enter the following into the command line.

        echo "Testing ssmtp on the SBC" | ssmtp destinationEmailAddress@emailDomain.com
            
            

If all goes well, the email will be delivered to the recipient. If not, double check your config file and make sure your email and password is correct.

For automated messages, it is useful to be able to send pre-written messages from text files. To do so, run ssmtp from the folder containing the message file and run the command:

        ssmtp destinationEmailAddress@emailDomain.com < message.txt
            

The text within message.txt should resemble the following. Note the empty line after Subject:.

        To: destinationEmailAddress@emailDomain.com[, emailAddress2@anotherDomain.com]
        From: Sender Name (or sender email address)
        Subject: Email Subject

        This is my email body
            

IMPORTANT NOTE: The To: heading of the message file does NOT affect the actual recipients of the email, only the metadata that gets sent with it. You can also omit the To: heading entirely to bcc all recipients to keep their addresses private from each other.

To send an email to multiple recipients, add them to the command as follows:

            
        ssmtp destinationEmailAddress@emailDomain.com emailAddress2@anotherDomain.com < message.txt
            

After sending a message using a file like the one above, with the To: field omitted, the recipients will receive an email that looks something like this:

SMS Messages

Now that we can send emails from the SBC, we can use the same feature to send SMS text messages. Most cellphone providers have an email to SMS service that can be used to send text messages from a computer for free, so long as you know the carrier the number is on.

These generally are of the form phoneNumber@carrier.specific.domain. They are listed in many places across the internet, and vary from country to country, so will not be listed here.

The end result of emailing one of these domains will look something like this:

Conclusion

Sending email and SMS text messages can be done quickly and easily using SSMTP.