Skip to content

Instantly share code, notes, and snippets.

@Maeglin73
Last active April 28, 2023 03:36
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Maeglin73/72eb5b1e4ee66a383c2aa454726be9a5 to your computer and use it in GitHub Desktop.
Save Maeglin73/72eb5b1e4ee66a383c2aa454726be9a5 to your computer and use it in GitHub Desktop.
How to get Sendmail to speak LMTP to GNU Mailman3

Sendmail and Mailman3 - Solving the LMTP problem

Current versions of Sendmail can speak LMTP to local processes, but how to make that happen seems poorly documented. When trying to get it to talk to GNU Mailman3 recently, I found next to no documentation, and a lot of people asking how to do it, so I'm leaving this here in the hopes that it helps someone.

This document shows a simplified example of how I did it on my Ubuntu 20.04 system, at least in terms of Sendmail configuration. While I'm using a "lists" subdomain, that seems entirely optional with this technique.

virtusertable

test@lists.example.com  %1%3@lists.example.com.private
@lists.example.com      error:5.1.1:550 User unknown

While this isn't a complete set of aliases for a Mailman mailing list, it does show how to create them. "%1%3" on right becomes the original user part of the recipient address, including the + and everything after it for things like bounce and confirmation replies. The .private TLD is officially reserved for private use, and seemed like the safest choice.

It is possible to make this even simpler, creating a catch-all alias and sending everything for the lists subdomain to Mailman, but defining individual aliases shifts the load of rejecting email to addresses that don't exist back to Sendmail, where it honestly belongs.

mailertable

lists.example.com.private      mm3lmtp:[localhost]

This basically takes the rewritten recipient domain from above, which doesn't actually resolve to anything, and directs it to the custom mailer defined below.

sendmail.mc

MAILER_DEFINITIONS
Mmm3lmtp,   P=[IPC], F=PSXmnz9, S=EnvFromSMTP/HdrFromSMTP,
                R=EnvToMM3, E=\r\n, L=1024,
                A=TCP $h 8024

LOCAL_RULESETS
SEnvToMM3
R$+                     $: $>EnvToSMTP $1
R$+ < @ lists . example . com . private > $*   $: $1 < @ lists . example . com . > $2

These additions define the custom mailer used in mailertable. The port number can be whatever you want to use in your installation. The EnvToMM3 rule adds on to Sendmail's default SMTP envelope recipient rewriting, removing the .private TLD that was added in virtusertable in the process of forwarding email to the LMTP server.

@ghjm
Copy link

ghjm commented Apr 28, 2023

I can confirm this works. Thanks for putting it together. However, I think Github, or the copy-and-paste process, or my browser, has converted the tabs in the sendmail.mc commands to spaces. Sendmail cares about this and won't work with only spaces. If anyone else runs into this, the proper places to put tabs are:

MAILER_DEFINITIONS
Mmm3lmtp,   P=[IPC], F=PSXmnz9, S=EnvFromSMTP/HdrFromSMTP,
TAB TAB R=EnvToMM3, E=\r\n, L=1024,
TAB TAB A=TCP $h 8024

LOCAL_RULESETS
SEnvToMM3
R$+ TAB TAB TAB $: $>EnvToSMTP $1
R$+ < @ lists . example . com . private > $* TAB $: $1 < @ lists . example . com . > $2

It's okay to mix spaces in with the tabs, and you don't have to use multiple tabs where I've shown them. But it is required that there be at least one tab character in each of these places.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment