1 =============================
2 Hooking up your mail server
3 =============================
5 Mailman needs to communicate with your *MTA* (*mail transport agent*
6 or *mail server*, the software which handles sending mail across the
7 Internet), both to accept incoming mail and to deliver outgoing mail.
8 Mailman itself never delivers messages to the end user. It sends them
9 to its immediate upstream MTA, which delivers them. In the same way,
10 Mailman never receives mail directly. Mail from outside always comes
13 Mailman accepts incoming messages from the MTA using the `Local Mail Transfer
14 Protocol`_ (LMTP_) interface. LMTP is much more efficient than spawning a
15 process just to do the delivery. Most open source MTAs support LMTP for local
16 delivery. If yours doesn't, and you need to use a different interface, please
17 ask on the `mailing list or on IRC`_.
19 Mailman passes all outgoing messages to the MTA using the `Simple Mail
20 Transfer Protocol`_ (SMTP_).
22 Cooperation between Mailman and the MTA requires some configuration of
23 both. MTA configuration differs for each of the available MTAs, and
24 there is a section for each one. Instructions for Postfix and Exim (v4)
25 are given below. We would really appreciate a contribution of a
26 configuration for Sendmail, and welcome information about other popular
27 open source mail servers.
29 Configuring Mailman to communicate with the MTA is straightforward, and
30 basically the same for all MTAs. Here are the default settings; if you need
31 to change them, edit your ``mailman.cfg`` file::
34 incoming: mailman.mta.postfix.LMTP
35 outgoing: mailman.mta.deliver.deliver
40 configuration: python:mailman.config.postfix
42 This configuration is for a system where Mailman and the MTA are on
45 Note that the modules that configure the communication protocol (especially
46 ``incoming``) are full-fledged Python modules, and may use these configuration
47 parameters to automatically configure the MTA to recognize the list addresses
48 and other attributes of the communication channel. This is why some
49 constraints on the format of attributes arise (e.g., ``lmtp_host``), even
50 though Mailman itself has no problem with them.
52 It is possible (although not documented here) to completely replace or
53 override the default mechanisms to handle both incoming and outgoing mail.
54 Mailman is highly customizable here!
56 The ``incoming`` and ``outgoing`` parameters identify the Python objects used
57 to communicate with the MTA. The ``python:`` scheme indicates that the paths
58 should be a dotted Python module specification. The ``deliver`` module used
59 in ``outgoing`` should be satisfactory for most MTAs. The ``postfix`` module
60 in ``incoming`` is specific to the Postfix MTA. See the section for your MTA
61 below for details on these parameters.
63 ``lmtp_host`` and ``lmtp_port`` are parameters which are used by Mailman, but
64 also will be passed to the MTA to identify the Mailman host. The "same host"
65 case is special; some MTAs (including Postfix) do not recognize "localhost",
66 and need the numerical IP address. If they are on different hosts,
67 ``lmtp_host`` should be set to the domain name or IP address of the Mailman
68 host. ``lmtp_port`` is fairly arbitrary (there is no standard port for LMTP).
69 Use any port convenient for your site. "8024" is as good as any, unless
70 another service is using it.
72 ``smtp_host`` and ``smtp_port`` are parameters used to identify the MTA to
73 Mailman. If the MTA and Mailman are on separate hosts, ``smtp_host`` should
74 be set to the domain name or IP address of the MTA host. ``smtp_port`` will
75 almost always be 25, which is the standard port for SMTP. (Some special site
76 configurations set it to a different port. If you need this, you probably
77 already know that, know why, and what to do, too!)
79 Mailman also provides many other configuration variables that you can
80 use to tweak performance for your operating environment. See the
81 ``src/mailman/config/schema.cfg`` file for details.
87 Postfix_ is an open source mail server by Wietse Venema.
93 You need to tell Mailman that you are using the Postfix mail server. In your
94 ``mailman.cfg`` file, add the following section::
97 incoming: mailman.mta.postfix.LMTP
98 outgoing: mailman.mta.deliver.deliver
99 lmtp_host: mail.example.com
101 smtp_host: mail.example.com
104 Some of these settings are already the default, so take a look at Mailman's
105 ``src/mailman/config/schema.cfg`` file for details. You'll need to change the
106 ``lmtp_host`` and ``smtp_host`` to the appropriate host names of course.
107 For everything on the same host, the default settings ``127.0.0.1`` and
108 ``localhost`` respectively are probably OK. If you do set ``smtp_host`` to
109 other than ``localhost``, make sure that host is in Postfix ``mynetworks``.
110 Generally, Postfix will listen for incoming SMTP connections on port 25.
111 Postfix will deliver via LMTP over port 24 by default, however if you are not
112 running Mailman as root, you'll need to change this to a higher port number,
116 Basic Postfix connections
117 -------------------------
119 There are several ways to hook Postfix up to Mailman, so here are the simplest
120 instructions. The following settings should be added to Postfix's ``main.cf``
123 Mailman supports a technique called `Variable Envelope Return Path`_ (VERP) to
124 disambiguate and accurately record bounces. By default Mailman's VERP
125 delimiter is the `+` sign, so adding this setting allows Postfix to properly
126 handle Mailman's VERP'd messages::
128 # Support the default VERP delimiter.
129 recipient_delimiter = +
131 In older versions of Postfix, unknown local recipients generated a temporary
132 failure. It's much better (and the default in newer Postfix releases) to
133 treat them as permanent failures. You can add this to your ``main.cf`` file
134 if needed (use the `postconf`_ command to check the defaults)::
136 unknown_local_recipient_reject_code = 550
138 While generally not necessary if you set ``recipient_delimiter`` as described
139 above, it's better for Postfix to not treat ``owner-`` and ``-request``
140 addresses specially::
142 owner_request_special = no
148 By default, Mailman works well with Postfix transport maps as a way to deliver
149 incoming messages to Mailman's LMTP server. Mailman will automatically write
150 the correct transport map when its ``mailman aliases`` command is run, or
151 whenever a mailing list is created or removed via other commands. Mailman
152 supports two type of transport map tables for Postfix, namely ``hash`` and
153 ``regexp``. Tables using hash are processed by ``postmap`` command. To use this
154 format, you should have ``postmap`` command available on the host running
155 Mailman. It is also the default one of the two. To connect Postfix to
156 Mailman's LMTP server, add the following to Postfix's ``main.cf`` file::
159 hash:/path-to-mailman/var/data/postfix_lmtp
160 local_recipient_maps =
161 hash:/path-to-mailman/var/data/postfix_lmtp
163 hash:/path-to-mailman/var/data/postfix_domains
165 where ``path-to-mailman`` is replaced with the actual path that you're running
168 Note that in the above and also below, if your current ``main.cf`` contains
169 settings for these items, including the default setting for
170 ``local_recipient_maps``, you should add the Mailman setting to the existing
171 setting rather than replacing it. For example::
173 local_recipient_maps = proxy:unix:passwd.byname $alias_maps
174 hash:/path-to-mailman/var/data/postfix_lmtp
176 Setting ``local_recipient_maps`` as well as ``transport_maps``
177 allows Postfix to properly reject all messages destined for non-existent local
178 users. Setting `relay_domains`_ means Postfix will start to accept mail for
179 newly added domains even if they are not part of `mydestination`_.
181 Note that if you are not using virtual domains, then `relay_domains`_ isn't
182 strictly needed (but it is harmless). All you need to do in this scenario is
183 to make sure that Postfix accepts mail for your one domain, normally by
184 including it in ``mydestination``.
186 Regular Expression tables remove the additional dependency of having ``postmap``
187 command available to Mailman. If you want to use ``regexp`` or Regular
188 Expression tables, then add the following to Postfix's ``main.cf`` file::
191 regexp:/path-to-mailman/var/data/postfix_lmtp
192 local_recipient_maps =
193 regexp:/path-to-mailman/var/data/postfix_lmtp
195 regexp:/path-to-mailman/var/data/postfix_domains
197 You will also have to instruct Mailman to generate regexp tables instead of hash
198 tables by adding the following configuration to ``mailman.cfg``::
201 incoming: mailman.mta.postfix.LMTP
202 outgoing: mailman.mta.deliver.deliver
203 lmtp_host: mail.example.com
205 smtp_host: mail.example.com
207 configuration: /path/to/postfix-mailman.cfg
209 See remarks above about ``lmtp_host`` and ``smtp_host``.
210 Also you will have to create another configuration file called as
211 ``postfix-mailman.cfg`` and add its path to the ``configuration`` parameter
212 above. The ``postfix-mailman.cfg`` would look like this::
215 transport_file_type: regex
218 Unusual Postfix configuration
219 -----------------------------
221 In some cases there will be an existing Postfix configuration in which the
222 domain that will be used for Mailman 3 lists is a `virtual alias domain`_ and
223 for various reasons, perhaps because it supports Mailman 2 lists and Mailman 3
224 lists need to use the same domain, it must remain a virtual alias domain.
225 This is a challenge because ``virtual alias domains`` do not use
226 ``transport_maps``. This section also applies if the domain is a `virtual
229 In order to enable this configuration, Mailman `domains`_ have an
230 ``alias_domain`` attribute. This is normally ``None`` but can be set to any
231 otherwise unused domain name. The ``alias_domain`` is a fictitious domain that
232 is not exposed in ``DNS`` and is only known to Postfix via the Mailman
233 generated mappings. For example if the actual domain is ``example.com`` the
234 ``alias_domain`` could be ``x.example.com`` or even literally ``bogus.domain``.
235 If you set an alias_domain and the configured MTA is Postfix, Mailman will create an
236 additional ``/path-to-mailman/var/data/postfix_vmap`` file with mappings from
237 the ``example.com`` addresses to the corresponding addresses in the
238 ``alias_domain`` and will use the ``alias_domain`` in the other files.
239 To use this feature, add the following in ``main.cf``::
242 hash:/path-to-mailman/var/data/postfix_lmtp
244 hash:/path-to-mailman/var/data/postfix_domains
246 hash:/path-to-mailman/var/data/postfix_vmap
248 where ``path-to-mailman`` is as above. If any of these are already set, just
249 add the ``hash`` references to the existing settings. We don't add
250 ``local_recipient_maps`` because the lists are in a virtual domain and are
251 therefore not local, although if you have lists in multiple domains, some of
252 which are local, you may need ``local_recipient_maps`` as above. Note that
253 these can be ``regexp`` tables rather than ``hash`` tables. See the
254 ``Transport maps`` section above.
256 Starting with version 3.3.6, it is possible to use Mailman's LMTP
257 service with Postfix' ``reject_unverified_recipient``.
259 Postfix documentation
260 ---------------------
262 For more information regarding how to configure Postfix, please see
263 `The official Postfix documentation`_,
264 `The reference page for all Postfix configuration parameters`_,
265 and the documentation for the `relay_domains`_, `mydestination`_ and
266 `virtual alias domain`_ settings.
268 .. _`The official Postfix documentation`:
269 http://www.postfix.org/documentation.html
270 .. _`The reference page for all Postfix configuration parameters`:
271 http://www.postfix.org/postconf.5.html
272 .. _`relay_domains`: http://www.postfix.org/postconf.5.html#relay_domains
273 .. _`mydestination`: http://www.postfix.org/postconf.5.html#mydestination
274 .. _`virtual alias domain`: http://www.postfix.org/ADDRESS_CLASS_README.html#virtual_alias_class
275 .. _`virtual mailbox domain`: http://www.postfix.org/ADDRESS_CLASS_README.html#virtual_mailbox_class
281 `Exim 4`_ is an MTA maintained by the `University of Cambridge`_ and
282 distributed by most open source OS distributions.
287 Add or edit a stanza like this in mailman.cfg::
290 # For all Exim4 installations.
291 incoming: mailman.mta.exim4.LMTP
292 outgoing: mailman.mta.deliver.deliver
293 # Typical single host with MTA and Mailman configuration.
294 # Adjust to your system's configuration.
295 # Exim happily works with the "localhost" alias rather than IP address.
298 # Mailman should not be run as root.
299 # Use any convenient port > 1024. 8024 is a convention, but can be
300 # changed if there is a conflict with other software using that port.
302 # smtp_port rarely needs to be set.
304 # Exim4-specific configuration parameter defaults. Currently empty.
305 configuration: python:mailman.config.exim4
307 For further information about these settings, see
308 ``mailman/config/schema.cfg``.
313 The configuration presented below is mostly boilerplate that allows Exim to
314 automatically discover your list addresses, and route both posts and
315 administrative messages to the right Mailman services. For this reason, the
316 `mailman.mta.exim4` module ends up with all methods being no-ops.
318 This configuration is field-tested in a Debian "conf.d"-style Exim
319 installation, with multiple configuration files that are assembled by a
320 Debian-specific script. If your Exim v4 installation is structured
321 differently, ignore the comments indicating location in the Debian
325 # /etc/exim4/conf.d/main/25_mm3_macros
326 # The colon-separated list of domains served by Mailman.
327 domainlist mm_domains=list.example.net
331 # MM3_HOME must be set to mailman's var directory, wherever it is
332 # according to your installation.
333 MM3_HOME=/opt/mailman/var
337 ################################################################
338 # The configuration below is boilerplate:
339 # you should not need to change it.
341 # The path to the list receipt (used as the required file when
342 # matching list addresses)
343 MM3_LISTCHK=MM3_HOME/lists/${local_part}.${domain}
345 # /etc/exim4/conf.d/router/455_mm3_router
348 domains = +mm_domains
349 require_files = MM3_LISTCHK
350 local_part_suffix_optional
351 local_part_suffix = \
352 -bounces : -bounces+* : \
353 -confirm : -confirm+* : \
355 -owner : -request : \
356 -subscribe : -unsubscribe
357 transport = mailman3_transport
359 # /etc/exim4/conf.d/transport/55_mm3_transport
366 rcpt_include_affixes = true
371 The most likely causes of failure to deliver to Mailman are typos in the
372 configuration, and errors in the ``MM3_HOME`` macro or the ``mm_domains``
373 list. Mismatches in the LMTP port could be a cause. Finally, Exim's router
374 configuration is order-sensitive. Especially if you are being tricky and
375 supporting Mailman 2 and Mailman 3 at the same time, you could have one shadow
378 Another issue, not specific to Exim, is Mailman's requirement that every
379 message have a ``Message-ID:`` header. Exim can ensure this if you add these
380 two lines to the ``mailman3_transport:`` section.
383 headers_remove = message-id
384 headers_add = "Message-ID: ${if def:header_message-id:{$h_message-id:}{<E${message_exim_id}@${qualify_domain}>}}"
386 Alternative setup using callout verification
387 --------------------------------------------
389 Starting with version 3.3.6, you can rely on Mailman's responce on
390 ``RCPT TO:`` LMTP command if mailman would accept the recipient
391 address as valid. This can be used in Exim to validate recipients
392 using callout verification.
395 # /etc/exim4/conf.d/main/25_mm3_macros
396 # The colon-separated list of domains served by Mailman.
397 domainlist mm_domains = list.example.net
398 # The port of your Mailman's LMTP service
401 # /etc/exim4/local_rcpt_callout (create file or append if already exists)
402 # Make callout verification for all domains served by Mailman.
405 # /etc/exim4/conf.d/router/455_mm3_router
408 domains = +mm_domains
409 # no further conditions, valid recipients are verified in
410 # acl_check_rcpt using callout verification
411 transport = mailman3_transport
413 # /etc/exim4/conf.d/transport/55_mm3_transport
420 rcpt_include_affixes = true
425 There is `copious documentation for Exim`_. The parts most relevant to
426 configuring communication with Mailman 3 are the chapters on the `accept
427 router`_ and the `LMTP transport`_. Unless you are already familiar
428 with Exim configuration, you probably want to start with the chapter on
429 `how Exim receives and delivers mail`_.
431 .. _`Exim 4`: http://www.exim.org/
432 .. _`University of Cambridge`: https://www.cam.ac.uk/
433 .. _`copious documentation for Exim`: http://www.exim.org/docs.html
434 .. _`accept router`: http://www.exim.org/exim-html-current/doc/html/spec_html/ch-the_accept_router.html
435 .. _`LMTP transport`: http://www.exim.org/exim-html-current/doc/html/spec_html/ch-the_lmtp_transport.html
436 .. _`how Exim receives and delivers mail`: http://www.exim.org/exim-html-current/doc/html/spec_html/ch-how_exim_receives_and_delivers_mail.html
442 qmail_ is a MTA written by djb_ and, though old and not updated, still
443 bulletproof and occassionally in use.
448 Mostly defaults in mailman.cfg::
451 # NullMTA is just implementing the interface and thus satisfying Mailman
452 # without doing anything fancy
453 incoming: mailman.mta.null.NullMTA
454 # Mailman should not be run as root.
455 # Use any convenient port > 1024. 8024 is a convention, but can be
456 # changed if there is a conflict with other software using that port.
459 This will listen on ``localhost:8024`` with LMTP and deliver outgoing messages
460 to ``localhost:25``. See ``mailman/config/schema.cfg`` for more information
466 It is assumed that qmail is configured to use the ``.qmail*`` files in a user’s
467 home directory, however the instructions should easily be adaptable to other
468 qmail configurations. However, it is required that Mailman has a (sub)domain
469 respectively a namespace on its own. A helper script called ``qmail-lmtp`` is
470 needed and can be found in the ``contrib/`` directory of the Mailman source
471 tree and assumed to be on ``$PATH`` here.
473 As qmail puts every namespace in the address, we have to filter it out again.
474 If your main domain is ``example.com`` and you assign ``lists.example.com`` to
475 the user ``mailman``, qmail will give you the destination address
476 ``mailman-spam@lists.example.com`` while it should actually be
477 ``spam@lists.example.com``. The second argument to ``qmail-lmtp`` defines
478 how many parts (separated by dashes) to filter out. The first argument
479 specifies the LMTP port of Mailman. An optional third argument specifies the
480 LMTP hostname to connect to (by default localhost).
481 Long story short, as user mailman:
485 % echo '|qmail-lmtp 8042 1' > .qmail # put appropriate values here
486 % ln -sf .qmail .qmail-default
489 .. _qmail: https://cr.yp.to/qmail.html
490 .. _djb: https://cr.yp.to
496 The core Mailman developers generally do not use Sendmail, so experience is
497 limited. Any and all contributions are welcome! There is one such
498 contribution on GitHub_ and another in comments at this issue_.
501 .. _GitHub: https://gist.github.com/Maeglin73/72eb5b1e4ee66a383c2aa454726be9a5
502 .. _issue: https://gitlab.com/mailman/mailman/-/issues/307#note_632495542
503 .. _`mailing list or on IRC`: START.html#contact-us
504 .. _`Local Mail Transfer Protocol`:
505 https://en.wikipedia.org/wiki/Local_Mail_Transfer_Protocol
506 .. _LMTP: http://www.faqs.org/rfcs/rfc2033.html
507 .. _`Simple Mail Transfer Protocol`:
508 https://en.wikipedia.org/wiki/Simple_Mail_Transfer_Protocol
509 .. _SMTP: http://www.faqs.org/rfcs/rfc5321.html
510 .. _Postfix: http://www.postfix.org
511 .. _`Variable Envelope Return Path`:
512 https://en.wikipedia.org/wiki/Variable_envelope_return_path
513 .. _postconf: http://www.postfix.org/postconf.1.html
514 .. _domains: ../model/docs/domains.html