Send an SMS from Unix/Linux Andrew Mallett | Updated August 2017

This script will send an SMS (and email) alert from a Unix/Linux box, based on any predefined event. This is very useful for busy sysadmins who (regrettably) can't spend all their time at the console..

From Unixbox to Mobile

The system uses an email app called SendEmail and an SMS subscription service. SendEmail is written in PERL so you will need to be running PERL on your system.


For Ubuntu and similar distros, run the following command to install sendEmail..

sudo apt-get install sendemail

Otherwise the archive an be obtained from Caspian's Homepage. After extracting the tarball, copy the single sendEmail script to the /usr/local/sbin directory, which being in the system path, is then invokable from anywhere in the directory tree, just like the native Unix sendmail.

There are various SMS subscription services which basically convert an email to an SMS message. I use messagenet.com.au who offer an inexpensive and reliable service.

Bringing it all together

The sendEmail function comes with clearly documented Usage Instructions and examples. Here is one of my own shell scripts sms.sh, used for sending off an SMS-email..

#Andy's Emailer using sendEmail

sendEmail -f sender@domain.com \
          -t 04091234567@messagenet.com.au \
          -s sendmail.yoursmtpserver.com \
          -xu secure_smtp_username \
          -xp secure_smtp_passwd \
          -u "66666 Test SMS" \
          -m "This is a test SMS from your Unix Server.." \

In the above example, sendEmail is invoked with the following parameters:

-f  (from:) - specifies the sender's email address
-t  (to:) - destination address, in this case a mobile number at messagenet.com.au
-s  (smtp) - name of SMTP server
-xu (secure username) - authorised username for secure SMTP servers
-xp (secure passwd) - authorised user's password for secure SMTP servers
-u   (subject) - subject line
-m   (message) - message

Note that the subject line contains the number, 66666. This is the password number for the messagenet service, which must be included in the subject line or message body. It is used to prevent SMS spamming and other abuse of the SMS-email system and is stripped out of the final SMS message.

Don't forget to make the original sendEmail PERL script and your own email sending script executable before running them.

This system is basically the same as sending any old email and so requires the use of a bona fide SMTP Server to send the email out. I use one of my web hosting service's Mail Servers but your ISP's default Mail Server should do the job.

Although the Usage Instructions imply the -xu and -xp switches are not normally used (listed, amusingly, under the Paranormal section), I would suggest that most mail servers these days use secure SMTP to reduce spam and will require an authorised user's credentials to send an email. This system can of course be used to send normal emails too.