reversed(top()) code tags rss about

Removing sendmail from mail receiving chain

July 4, 2014
[mail] [gnu/linux] [howto]

One of common ways to receive mail includes using sendmail as an MTA. This causes some inconvenience especially when it’s the only purpose sendmail is installed for. To be able to receive mail sendmail deamon must be running all the time, which also means that it consumes some (small) amount of resources. It’s not a problem at all (even though it slows down system startup a little bit), but why keep it if we can live without it?

Generic scheme of receiving mail is as follows:

![Standard mail chain][standard-mail-chain]

Here sendmail passes all mail it gets to procmail, which is configured in ~/.forward file. The idea is to get rid of sendmail such that:

  • It won’t be started with system.
  • It won’t be listening to any sockets.
  • Nothing will be forwarded to it.
  • No need to keep that ~/.forward file.

This means that all the mail will be passed directly to MDA, which is procmail in this case.

It turned out to be quite easy to implement after reading this nice post even though it’s not exactly what the subject. The most useful line is this one:

mda "/usr/bin/procmail -m /path/to/procmail.conf"

man fetchmail says:

mda                -m           Specify MDA for local delivery

It’s strange thing that (I guess) all articles I’ve ever read on this topic do not mention this useful option of fetchmail. And leave it with default behaviour of sending mail to localhost SMTP server.

For Maildir format all one needs to cut sendmail from this chain is to set this option, but there is one caveat not described in the article linked above. The option must be set for each account in your fetchmail configuration file, e.g.:

# ...

poll mail.example.com proto pop3
       user 'me' with pass '123' is 'meagain' here ssl keep

mda "/usr/bin/procmail -m ~/.config/procmail/procmail.conf"

poll anothermail.example.com proto pop3
       user 'meagain' with pass 'qwerty' is 'meagain' here ssl keep

mda "/usr/bin/procmail -m ~/.config/procmail/procmail.conf"

If you forget to specify mda option for one of accounts, log of fetchmail will contain messages like this:

fetchmail: Connection errors for this poll:
name 0: connection to localhost:smtp [127.0.0.1/25] failed: Connection refused.
fetchmail: SMTP connect to localhost failed
fetchmail: SMTP transaction error while fetching from mail.example.com and
delivering to SMTP host localhost
fetchmail: Query status=10 (SMTP)

For Mailbox format, it wont work out of the box because it requires leading From ... line for every contained message and won’t work well: new mail will be delivered, but won’t be visible in mail client (mutt). Basically one needs to specify -f - option for procmail, which:

-f fromwhom
      Causes  procmail  to  regenerate  the leading `From ' line with fromwhom
      as the sender (instead of -f one could use the alternate and obsolete
      -r).  If fromwhom consists merely of a single `-', then procmail will
      only update the timestamp on the `From ' line (if present, if not, it
      will generate a  new one).

Read this page of mutt FAQ for more details.

P.S. The image at the top was generated with ditaa, which is a nice tool for small and simple diagrams like that one.