Skip to main content

msmtp – a (fairly) simple mail submission program

As an oldtime Unix guy, I’ve always been used to having the BSD mail utility to hand, and a suitably configured mail system, so that I can script jobs to run and email the results back to me. I use mail as a sort of glorified syslog facility. With smaller single board Linux computers we don’t always want to install a full mail setup – resources often tend to be limited. A few years back I discovered msmtp

This utility is an smtp client that submits a file in standard mail format to a mail server. It can submit plain text email or use TLS/SSL etc. I use a couple of script wrappers to emulate, sort of, sendmail and the sending part of the BSD mail utility.

Of course to use msmtp you need a mail server to which you can submit email for delivery. My home server is my mail server, but you could use your ISP’s smtp server. Another problem is that msmtp just fails if it can’t connect to the mail server – it’s up to you to handle that and do something else with that precious message you can’t mail just now! My sample scripts do not deal with that situation.

This very simple script I call sendmail, and it will need customising for your setup…


# set these for your setup...
From="[email protected]"

exec msmtp --host=$MailServer --domain=$Domain --from=$From $*

This is my simple script to emulate the simple parts of the send functionality in the BSD mail utility. It has many shortcomings, but it has served me well…

# A sort of shell replacment for the send functionality of
# the standard "mail" utility.
# mail [-s subject] recipient(s)

u=`id -un`

while [ $# -gt 0 ]; do
 case "$p" in
        if [ $# -gt 0 ]; then shift ; fi
        echo 1>&2 "Option "$p" not recognised."
        exit 1
        r="$r , $p"
if [ "$r" = "" ]; then
 echo 1>&2 "No Recipients."
 exit 1
if [ "$s" = "" ]; then
 printf "Subject: "
 read s

s="Subject: $s n"

(echo -e "From: ${u}@$d nTo: $r n$s nn"
 cat ) | sendmail -t $v

So if you have a job to run on the platform, then this will email the output to you…

my_job | mail -s “my_job output” [email protected]

msmtp can be loaded from the package systems of most distributions, but I have had occasion to cross-compile the package for installing on a system without package management. I had only limited libraries on my cross compile system, and found that after downloading and extracting the sourcecode from sourceforge, I had to cross compile without some of the advanced features. I used

./configure –build=arm –disable-ssl –disable-gsasl –disable-nls

before doing the make to build the binaries. The resultant binary just submitted plain text email, but that was ok for my use – YMMV. The resultant binary, suitably stripped,is pretty lean.

I recently revisited using msmtp to pre-test a change to my ISP’s new smtp server, before committing the change to my mailserver’s sendmail setup. It can also be useful for testing security settings etc on mail submissions systems.


Kermit lives!

As a veteran of the IT industry I’ve seen software and OSes come and go, but there are some pieces of software that I seem to have used on a lot of platforms for a lot of years. One of the oldest of these is the file transfer software Kermit, from Columbia University –

I’ve used kermit in the early 80′s, on various CP/M systems, the very first IBM PCs and on the BBC Micro, and have been using it since on various early Unices, and other OSes that are now only memories in old fogy minds like mine. I even used hacked versions of kermit for building an email system between various computers joined by rs232 links, and then gatewayed out to the big wide world in the late 1980′s.

I used it extensively in the 90′s for automating and controlling transfers and connections over dial-up modems. It is still my console of choice when I need to hook up microcontrollers and single board computers with rs232. It’s configurability, features and programmability make it second to none.

However it has always erked me that it’s licensing prevented it being available in the standard repositories of the major Linux distributions. I have got used to downloading the source tar ball and compiling my own executables whenever I’ve needed kermit, and cursed silently that yum or apt-get would not simply do the job for me.

So imagine my joy when I belatedly discovered that Columbia University have cancelled the Kermit project and allowed it to be re-licensed and development continue at The new license is a Revised 3-Clause BSD License which will at last allow Kermit to join the Free Software Family as a full member – and about time too!

If you are not familiar with Kermit, and need to go beyond where minicom etc can take you, then do check it out. It might appear a bit old school but it is very, very powerfull.


Resuming stalled or held CUPS print jobs…

I have a network printer, and it’s surprising how often I print a job and then find the printer is not switched on, and the print job gets put in HOLD state. Using “lpstat -l” one can view the print job status, and with the “lp” command can resume the print job. But I’m idle, so I created this very simple script to do it all in one command – I call it “lprel”.

# script to resume the top job on the default printer queue

j=`lpstat | head -1 | cut -d' ' -f1`
if [ "$j" = "" ]; then
  echo 1>&2 "No jobs in queue."
  exit 1
echo "releasing "$j"..."
lp -i "$j" -H resume
lpstat -l