Custom mail delivery solutions
How mail is delivered
First, a recap of the basics. How does mail from far away get to
your account - say - email@example.com ?
- The remote mail client probably punts the mail to a smarter
host - the SMTP server of their ISP ( Internet Service Provider ).
this will have been configured when first setting up their
- Their ISP mail server will ask a local nameserver for the
Mail Exchanger records of my-domain.com. These are machines
listed as handling mail for this domain. The ISP will try to deliver
directly to the lowest-numbered MX record in the list, via SMTP. If
it cannot connect, it will try other MX hosts, usually in ascending
- In this last step, or via secondary MX hosts, the mail will
eventually land on the target host - the lowest-numbered MX, often
your local ISP you have contracted for this service.
Most of the time, your ISP will dump all the mail for that domain
into a single mailbox, and leave you to figure the rest.
If this is the case, your best, and only, solution below is
Fetchmail uses POP3 or IMAP to get mail from your server.
Fetchmail's limitations are mostly to do with the fact that the SMTP
envelope information has been discarded on delivery to your mailbox,
though it has some creative (but not foolproof) ways to try to get
around the problem. See the section on
USE AND ABUSE OF MULTIDROP MAILBOXES in the fetchmail documentation.
Maybe your ISP is a little more cooperative. If you can get a
fixed IP address on dialup, you could list them as a Mail Exchanger,
but not the lowest, and yourself as the lowest. This will
only work if you have a fixed IP. See Fixed IP
Much of the messiness of this whole problem is that SMTP is not authenticated,
and therefore relies on name services - fixed IP addresses, to solve this.
One way to preserve the SMTP protocol across dynamic IP addresses is to
batch SMTP commands in a file, and pass the file over a separate transport.
Batched SMTP is similar to normal SMTP, but, because it is being written
to a file, means that all responses are ignored. Fortunately this is
not traumatic - if the protocol is written to a file assuming that
all responses will be OK it all works. See Batch SMTP below.
by Eric S. Raymond
Best to read the fetchmail docs. Fetchmail by default delivers the
mail to a local SMTP server. Be careful to tell that local SMTP
server to treat your domain as local, otherwise it may punt the
mail to your local ISP as a smarthost (as you should be doing with
all your other mail) and you will have a mail loop.
For a single user Linux box, I prefer to configure fetchmail with the
'--mda' (mail delivery agent) option, pointed to procmail, so I
can leave my SMTP server (if I run one - why bother ?) in a basic
Administrative access to SMTP server
- If You control the machine to which the mail is delivered,
in particular if you control the SMTP server configuration, you have
other options. One of the easiest options is to add a custom header
for the envelope recipient so that fetchmail can reliably do its thing
(adding X-Envelope-To: header, for instance) and
continue with fetchmail.
- Still with us, eh ? To look past here, you must be able to edit
your SMTP server configuration file. If you are the administrator of
the machine, and the machine only handles your mail, I recommend you
install either exim or qmail as your SMTP server. qmail is very
capable, but I do not cover it here. There are better help texts
available on the qmail site.
For exim see below.
Maybe you have an account on a 'virtual server' that runs daemon services
chrooted in your home directory on your behalf. I have used these,
and they have always run sendmail.
Use a custom X-Envelope-To: header and use fetchmail .. really.
Do you have a fixed IP address ? If you do not,
it is worth a little time to see if you can get one. My ISP gave me a
fixed IP address even though I dial up to their general modem pool -
Great !! I think that is a feature of their Portmasters.
A private line will usually get you a fixed IP address.
If you can get a fixed IP address on dialup, you could list them as a
Mail Exchanger, but not the lowest, and yourself as the lowest.
The Sendmail ETRN command will tickle the remote
SMTP server to deliver your mail after dialing up.
You need a recent version of sendmail at your server (ISP). Less than
8.8.x will not work. A simple way to find out if your server has the
requisite software is to :-
telnet mail.my-isp.net 25
You are looking for ETRN as a valid command.
Sendmail can be found at www.sendmail.org along
with all sorts of other useful sendmail stuff.
You now need to set up your MX records for proper delivery of mail. It will eventually
look something like this. For your domain "my-domain.com",
and your ISP "my-isp.net" :-
$ nslookup -type=mx my-domain.com
my-domain.com preference = 10, mail exchanger = my-domain.com
my-domain.com preference = 20, mail exchanger = mail.my-isp.net
This means that if you are online, mail for your domain will be
delivered directly to your machine. If you are offline, it will be
spooled at mail.my-isp.net. When your connection comes up, execute the
following simple script :-
# Send ETRN command to sendmail 8.8.x - Andy Rabagliati <firstname.lastname@example.org>
telnet mail.my-isp.net smtp <<SMTP_EOF
# End of Shell script
And Bob's your uncle, as we say. I used to have a perl / finger script that would do this,
but it was perl4, and past its time ..
There is a good description of other alternatives at http://www.swinc.com/resource/exch_dq.htm
though those intructions are aimed at MS Exchange users.
Next Batched mail solutions