Troubleshooters.Com and T.C Linux Library Present

Emailing Out:
Nullmailer and Kmail:
The Tiny Mail Transfer Agent

Copyright (C) 2007, 2011 by Steve Litt, All rights reserved. Material provided as-is, use at your own risk. 


Contents

Disclaimer

This page is an introduction to sending email without a full blown MTA -- not an authoritative text. This page may have errors -- in fact it probably does. DO NOT trust what you see on this page without verifying it for yourself. I am not responsible for any damage or injury caused by your use of this document, or caused by errors and/or omissions in this document. If that's not acceptable to you, you may not use this document. By using this document you are accepting this disclaimer.

The techniques in this document could be used to send spam. Don't do it. You could find yourself fined, prosecuted, and you'll certainly find yourself ostracised. If the people aren't your existing customers, don't do it.

Introduction

I'm pretty good at Linux, but configuring sendmail and postfix if far beyond my capabilities. For the most part it doesn't matter because I use either my ISP's or my web host's SMTP server, and I use Kmail, which has a built-in SMTP client to transfer directly to those SMTP servers (MTA's).

But now orders for my Ebooks have gotten frequent enough that I'd prefer to create and email them with a process instead of manually. Trouble is, the mail executable requires an MTA. Sendmail and Postfix are out of the question -- they're way too complex, and if you do them wrong you've just become an open relay for the world's spammers.

So I used nullmailer.

Nullmailer is a tiny MTA, including a sendmail decoy that pretends it's sendmail. When you run the mail executable, it triggers the sendmail decoy, which calls the nullmailer-send program.

Nullmailer can be difficult. Very, very difficult. It can appear as a black box. Internet documentation for Nullmailer is incomplete, to say the least. So is the documentation that comes with it. Yes, I know, they tell you to "put your host in the defaulthost file", but please, WHICH host? The one for my computer? The one for my ISP? They don't say -- the just gleefully go on spouting docs so incomplete they're meaningless. Although this document isn't complete either, I hope it's complete when telling you what to put in which nullmailer variables, thus completing the rest of the docs for nullmailer.

However, the best of plans sometimes go astray, so as a fallback, at the end of this document I show an ultimate kludge to mass-mail with, of all things, Kmail.

Installing Nullmailer

Here I'll do just what I accused other documenters of and tell you to install with your package manager, or else grab the source and compile. I know that Ubuntu 11.04 has a functional Nullmailer package -- I'm currently using it.

YOUR FIRST STEP -- Yes, I'm Shouting

I'm going to tell you a sad, tragic story of a week of lost wages. All because I didn't do this first step. I spent a couple days troubleshooting nullmailer, then, doing a diagnostic test, I accidentally erased everything in /etc and had to reinstall. Then it took me another three days to get nullmailer working. That whole time I told everyone who would listen that nullmailer was a no good black box, and I was fin

MAKE SURE YOU HAVE A WORKING EMAIL SENDING PROTOCOL!  If you use Kmail, use the one from Kmail. If you use Eudora, use the one from Eudora. If you use Evolution, use the one from Evolution. Make sure you can send from one of those, then record the protocol. At a minimum you need the following info:
The last three of the preceding usually aren't used. The password usually the same password you use to retrieve your email (POP or IMAP)

If you have TLS encryption, there is some documentation on the Internet about how to do that, but MAKE ABSOLUTELY SURE it works on Kmail or whatever before trying it in Nullmailer. If in Kmail it tells you something about accepting an unknown certificate, that's probably going to stop you dead in Nullmailer -- that's what it did to me.

All this info should be available from your ISP, although it's usually given as a series of MS Outlook commands. My main point is, make sure you have all this working on Kmail or Eudora or Evolution or Mozilla Thunderbird or Balsa or Sylpheed or something like them, before you try it on Nullmailer, and once you try it on Nullmailer, make sure you copy it all exactly into Nullmailer's configuration.

Configuring Nullmailer

On Ubuntu 11.04's Nullmailer, and I'd assume other Nullmailer distributions, configuration is done in the /etc/nullmailer directory. There's one file, called remotes, that's always necessary, because it defines your ISP's SMTP mail server (the mail server to which you send your email). The remotes file has the following format:
smtpserver.your-isp.com smtp --port=<portno> --user=<loginname> --pass=<yourpassword>

These were all the info you collected in the preceding article. If your authorization type is "Login", you might need a --login-auth argument also.

You're probably going to also need to configure a file called me and one called defaulthost. Each will probably need to contain your ISP's domain name, e.g. your-isp.com.

Nullmailer Mechanics: A Simplified View

My nullmailer came with four executables:
This is all based on a mail queue in which newly created emails are placed, and from which they are sent. New emails are placed in the queue by nullmailer-inject, which takes the basic email file and tweaks it a little bit, adding other headers. I'm not sure, but I think other executables like mail and sendmail use nullmailer-inject to queue up messages. Note that things like the real SMTP Sendmail and Postfix are mutually exclusive with Nullmailer -- if you have either you don't have Nullmailer and vice versa, so Nullmailer replaces the sendmail executable with one of its own, which I believe calls nullmailer-inject.

The sending part is done by nullmailer-send, a continuously running program that every once in a while sends some more queued messages. Also, when nullmailer-inject places a new message, it wakes up nullmailer-send so the new message can be sent immediatly, if the queue is close to empty.

As a practical matter, on a desktop computer the queue will always be almost empty except in the following circumstances:
  1. You just ran software to place a hundred or so new messages via nullmailer-inject.
  2. Many of your queued messages are in error so they're never sent and deleted.
As far as nullmailer-queue, I have no idea what it does, unless perhaps nullmailer-inject calls it to do some of the work.

The mailq program lists the emails still in the queue, making it a valuable troubleshooting tool, although those messages can still be seen by looking in the Nullmailer queue directory.

Special Directories

Nullmailer uses some special directories. One excellent way to find them all (and all other files related to Nullmailer) is to do something like this:
locate -i nullmail > nullmailer.files
Be sure to update the tree for the locate command before doing so. On my computer, you update it with sudo updatedb.

One is its configuration directory where it keeps its configuration files.

Configuration Directory

On my computer the configuration directory is /etc/nullmailer. The one file this directory must contain is remotes, which tells Nullmailer which SMTP server to send the email to, and how to interact with that SMTP server. There are several other possible config files:
File
Used by
Use
remotes
nullmailer-send
Defines the SMTP server(s) to which you send email, and the protocol with which to access them.
me
nullmailer-inject Badly documented, but my experiments tell me its best to put your ISP's domain name here.
defaulthost nullmailer-inject Overrides the hostname in /etc/mailhost. As a practical matter, it's often necessary to set this to the domain name of your ISP, e.g. earthlink.net.
defaultdomain nullmailer-inject If the hostname determined by the defaulthost file or /etc/mailname has no dots, then this is bolted on at the back of that hostname.
pausetime nullmailer-send From the man page:  The  number  of  seconds  to pause between successive queue runs when there are messages in the queue (defaults to 60).  If  this              is  set  to 0, nullmailer-send will exit immediately after going through the queue once (one-shot mode).

In other words, how many seconds will you wait to let messages accumulate before sending them.
adminaddr nullmailer-queue The email address to whom Nullmailer sends failures and errors.
helohost
nullmailer-send More protocol stuff. Beyond the scope of this document.
sendtimeout
nullmailer-send The man page is unclear on this, but it appears to be a timeout on an individual message send and appears to default to one hour. One hour is probably an excellent value on dialup, but on a properly functioning high speed (10Mbps) Internet I can't imagine a realistic send from a home computer lasting more than ten minutes, and if the file is that big, you're probably going to run into limits at the SMTP server.

Queue Directory

The queue directory is where nullmailer-inject puts emails to be sent, and where nullmailer-send finds its emails to send, and then deletes the sent emails. Once again, the locate command is your friend. On my Ubuntu 11.04 computer it's /var/spool/nullmailer/queue.

In this directory you can watch the comings and goings of files, look at files, change files, and any other diagnostic tests you can think of.

Testing and Troubleshooting

On Ubuntu 11.04, the normal way to run nullmailer-send is with the following command:
service nullmailer start
The preceding command runs it as a daemon, which isn't what you want while testing and troubleshooting. You want it running in the foreground so you can see messages realtime. To do that, as user root run it like this:
nullmailer-send
Here's a nice script that can send a test message on a Linux computer, obviously after you set variables for names and email addresses in the top section:
=================================
#!/bin/bash

# START OF USER CHANGABLE VARIABLES
sender=yourself@yourdomain.com     ##### MUST BE YOUR EMAIL AT THE SMTP SERVER
youremail=$sender                  ##### FEEL FREE TO MAKE IT SOMETHING ELSE
                                   #####   IF YOU HAVE A SECOND EMAIL ADDRESS
friendemail=friend@friendsdomain.com

yourname="Yourfirst Yourlast"
friendname="Friendfirst Friendlast"
#  END  OF USER CHANGABLE VARIABLES


emailfile=myemail.email
dtime=`date`
ltlt="<"
gtgt=">"

echo "Subject: Nullmailer test at $dtime" > $emailfile
echo "From: $yourname  $ltlt$sender$gtgt" >> $emailfile
echo "To: $yourname  $ltlt$youremail$gtgt" >> $emailfile
echo "Cc: $friendname $ltlt$friendemail$gtgt" >> $emailfile
echo "" >> $emailfile
echo "Sent at $dtime" >> $emailfile
echo "" >> $emailfile
echo "$yourname was here" >> $emailfile
echo "and now is gone" >> $emailfile
echo "but left his name" >> $emailfile
echo "to carry on." >> $emailfile
echo "" >> $emailfile
echo "This is a second paragraph thats kinda long, really really long, so long that I truly hope that it does the right thing and wraps." >> $emailfile
echo "" >> $emailfile
echo "Sincerely" >> $emailfile
echo "$yourname" >> $emailfile

cat $emailfile | nullmailer-inject -h

=================================

If you look at myemail.email you can see what the raw file looks like.

Notice the -h argument for nullmailer-inject. That means use only the addresses in the file header, and nothing on the command line argument. I did that so all the addresses are in one place, the file, which makes things less confusing.
Dufus Alert

If any of your recipients is a mailing list, make sure your sender address is a member of that mailing list, or else your message won't go through. Sounds obvious, right? Well, as the possessor of multiple email addresses, I got nailed by this obvious dufus move and lost a half hour trying to figure it out.

Getting it to Work With Mutt

You might find that Mutt doesn't work with Nullmailer.

You know why Mutt doesn't work with nullmailer? Because Mutt uses the environment variable $EMAIL as the sender address, and this address is typically a local address instead of something at your ISP or anything else on the Internet under control of the global DNS system. So the SMTP server drops the message on the floor.

Here's a script you can use to get Mutt to work with Nullmailer:
=========================================
#!/bin/bash
oldemail=$EMAIL
EMAIL=your-email@your-isp.com
export EMAIL
mutt

=========================================
The preceding makes sure that Mutt's "From" header is your-email@your-isp.com, not something on your local box.



Back to Troubleshooters.Com * Back to Linux Library