« Back to blog

Sending email from a script with sendEmail

This is one of those rare gems - an open source program which is unbelievably simple, elegant and useful. It only does one thing, and it does it well. sendEmail is an email program for sending SMTP mail from the command line. It's written in Perl and doesn't use any external modules, making it perfect for a situation where you want something that 'just works'.

Getting it working

As an Ubuntu user, installing it was as simple as:

sudo apt-get install sendemail

There are also RPM and Windows EXE versions available at the site, as well as the source code. Once installed, just type sendEmail ... to see a breakdown of the command line options.

I wrote the following one-liner to allow me to quickly send a copy of something I'm working on to my gmail - perfect for keeping on-the-fly backups of scripts.

sendEmail -f example@gmail.com -t example@gmail.com -u "[send2gmail] $1" -m "File $1 attached" -a "$1" -s smtp.example.com:25

(Just replace smtp.example.com with your ISP's smtp server and pop your gmail address in place of example@gmail.com). I also use it to backup all of my subversion repos and mysql databases - encrypted of course - to my gmail account each night via a cron job.