Table of Contents for
Postfix: The Definitive Guide

Version ebook / Retour

Cover image for bash Cookbook, 2nd Edition Postfix: The Definitive Guide by Kyle D. Dent Published by O'Reilly Media, Inc., 2003
  1. Postfix: The Definitive Guide
  2. Cover
  3. Postfix: The Definitive Guide
  4. Foreword
  5. Preface
  6. Audience
  7. Organization
  8. Conventions Used in This Book
  9. Comments and Questions
  10. Acknowledgments
  11. 1. Introduction
  12. 1.1. Postfix Origins and Philosophy
  13. 1.2. Email and the Internet
  14. 1.3. The Role of Postfix
  15. 1.4. Postfix Security
  16. 1.5. Additional Information and How to Obtain Postfix
  17. 2. Prerequisites
  18. 2.1. Unix Topics
  19. 2.2. Email Topics
  20. 3. Postfix Architecture
  21. 3.1. Postfix Components
  22. 3.2. How Messages Enter the Postfix System
  23. 3.3. The Postfix Queue
  24. 3.4. Mail Delivery
  25. 3.5. Tracing a Message Through Postfix
  26. 4. General Configuration and Administration
  27. 4.1. Starting Postfix the First Time
  28. 4.2. Configuration Files
  29. 4.3. Important Configuration Considerations
  30. 4.4. Administration
  31. 4.5. master.cf
  32. 4.6. Receiving Limits
  33. 4.7. Rewriting Addresses
  34. 4.8. chroot
  35. 4.9. Documentation
  36. 5. Queue Management
  37. 5.1. How qmgr Works
  38. 5.2. Queue Tools
  39. 6. Email and DNS
  40. 6.1. DNS Overview
  41. 6.2. Email Routing
  42. 6.3. Postfix and DNS
  43. 6.4. Common Problems
  44. 7. Local Delivery and POP/IMAP
  45. 7.1. Postfix Delivery Transports
  46. 7.2. Message Store Formats
  47. 7.3. Local Delivery
  48. 7.4. POP and IMAP
  49. 7.5. Local Mail Transfer Protocol
  50. 8. Hosting Multiple Domains
  51. 8.1. Shared Domains with System Accounts
  52. 8.2. Separate Domains with System Accounts
  53. 8.3. Separate Domains with Virtual Accounts
  54. 8.4. Separate Message Store
  55. 8.5. Delivery to Commands
  56. 9. Mail Relaying
  57. 9.1. Backup MX
  58. 9.2. Transport Maps
  59. 9.3. Inbound Mail Gateway
  60. 9.4. Outbound Mail Relay
  61. 9.5. UUCP, Fax, and Other Deliveries
  62. 10. Mailing Lists
  63. 10.1. Simple Mailing Lists
  64. 10.2. Mailing-List Managers
  65. 11. Blocking Unsolicited Bulk Email
  66. 11.1. The Nature of Spam
  67. 11.2. The Problem of Spam
  68. 11.3. Open Relays
  69. 11.4. Spam Detection
  70. 11.5. Anti-Spam Actions
  71. 11.6. Postfix Configuration
  72. 11.7. Client-Detection Rules
  73. 11.8. Strict Syntax Parameters
  74. 11.9. Content-Checking
  75. 11.10. Customized Restriction Classes
  76. 11.11. Postfix Anti-Spam Example
  77. 12. SASL Authentication
  78. 12.1. SASL Overview
  79. 12.2. Postfix and SASL
  80. 12.3. Configuring Postfix for SASL
  81. 12.4. Testing Your Authentication Configuration
  82. 12.5. SMTP Client Authentication
  83. 13. Transport Layer Security
  84. 13.1. Postfix and TLS
  85. 13.2. TLS Certificates
  86. 14. Content Filtering
  87. 14.1. Command-Based Filtering
  88. 14.2. Daemon-Based Filtering
  89. 14.3. Other Considerations
  90. 15. External Databases
  91. 15.1. MySQL
  92. 15.2. LDAP
  93. A. Configuration Parameters
  94. A.1. Postfix Parameter Reference
  95. 2bounce_notice_recipient
  96. access_map_reject_code
  97. alias_maps
  98. allow_mail_to_files
  99. allow_percent_hack
  100. alternate_config_directories
  101. append_at_myorigin
  102. authorized_verp_clients
  103. berkeley_db_read_buffer_size
  104. biff
  105. body_checks_size_limit
  106. bounce_service_name
  107. canonical_maps
  108. command_directory
  109. command_time_limit
  110. content_filter
  111. daemon_timeout
  112. debug_peer_list
  113. default_destination_concurrency_limit
  114. default_extra_recipient_limit
  115. default_process_limit
  116. default_recipient_limit
  117. default_verp_delimiters
  118. defer_service_name
  119. delay_notice_recipient
  120. deliver_lock_attempts
  121. disable_dns_lookups
  122. disable_mime_output_conversion
  123. disable_vrfy_command
  124. double_bounce_sender
  125. empty_address_recipient
  126. error_service_name
  127. export_environment
  128. fallback_relay
  129. fast_flush_domains
  130. fast_flush_refresh_time
  131. fork_attempts
  132. forward_expansion_filter
  133. hash_queue_depth
  134. header_address_token_limit
  135. header_size_limit
  136. home_mailbox
  137. ignore_mx_lookup_error
  138. in_flow_delay
  139. initial_destination_concurrency
  140. ipc_idle
  141. line_length_limit
  142. lmtp_connect_timeout
  143. lmtp_data_init_timeout
  144. lmtp_lhlo_timeout
  145. lmtp_quit_timeout
  146. lmtp_rset_timeout
  147. lmtp_tcp_port
  148. local_destination_concurrency_limit
  149. local_recipient_maps
  150. luser_relay
  151. mail_owner
  152. mail_spool_directory
  153. mailbox_command
  154. mailbox_delivery_lock
  155. mailbox_transport
  156. manpage_directory
  157. masquerade_domains
  158. max_idle
  159. maximal_backoff_time
  160. message_size_limit
  161. mime_header_checks
  162. minimal_backoff_time
  163. mydomain
  164. mynetworks
  165. myorigin
  166. newaliases_path
  167. notify_classes
  168. parent_domain_matches_subdomains
  169. pickup_service_name
  170. process_id_directory
  171. proxy_interfaces
  172. qmgr_clog_warn_time
  173. qmgr_message_active_limit
  174. qmgr_message_recipient_minimum
  175. qmqpd_error_delay
  176. queue_directory
  177. queue_run_delay
  178. rbl_reply_maps
  179. recipient_canonical_maps
  180. reject_code
  181. relay_domains_reject_code
  182. relay_transport
  183. relocated_maps
  184. resolve_dequoted_address
  185. sample_directory
  186. sendmail_path
  187. setgid_group
  188. showq_service_name
  189. smtp_bind_address
  190. smtp_data_done_timeout
  191. smtp_data_xfer_timeout
  192. smtp_destination_recipient_limit
  193. smtp_helo_timeout
  194. smtp_mail_timeout
  195. smtp_pix_workaround_delay_time
  196. smtp_quit_timeout
  197. smtp_rcpt_timeout
  198. smtp_skip_5xx_greeting
  199. smtpd_banner
  200. smtpd_data_restrictions
  201. smtpd_error_sleep_time
  202. smtpd_expansion_filter
  203. smtpd_helo_required
  204. smtpd_history_flush_threshold
  205. smtpd_noop_commands
  206. smtpd_recipient_limit
  207. smtpd_restriction_classes
  208. smtpd_soft_error_limit
  209. soft_bounce
  210. strict_7bit_headers
  211. strict_8bitmime_body
  212. strict_rfc821_envelopes
  213. swap_bangpath
  214. syslog_name
  215. transport_retry_time
  216. undisclosed_recipients_header
  217. unknown_client_reject_code
  218. unknown_local_recipient_reject_code
  219. unknown_virtual_alias_reject_code
  220. verp_delimiter_filter
  221. virtual_alias_maps
  222. virtual_mailbox_base
  223. virtual_mailbox_limit
  224. virtual_mailbox_maps
  225. virtual_transport
  226. B. Postfix Commands
  227. C. Compiling and Installing Postfix
  228. C.1. Obtaining Postfix
  229. C.2. Postfix Compiling Primer
  230. C.3. Building Postfix
  231. C.4. Installation
  232. C.5. Compiling Add-on Packages
  233. C.6. Common Problems
  234. C.7. Wrapping Things Up
  235. D. Frequently Asked Questions
  236. Index
  237. About the Author
  238. Colophon
  239. Copyright

Mailing-List Managers

Running mailing lists within Postfix is fine for static lists. But lists that change frequently are better handled by a mailing-list manager (MLM). With an MLM, the administrator of the list doesn’t have to manually edit the list file to add, delete, or change addresses because list members can subscribe and unsubscribe themselves. MLMs also support other features such as archiving of messages, digests of discussions, and the ability to moderate a list by allowing an administrator to review messages before they are posted to all members.

MLMs work by pointing normal Postfix aliases to commands that handle the distribution of messages and management of lists. MLMs use administrative aliases that point to programs to handle list functions such as subscribing and unsubscribing members from the list, handling bounced messages, and possibly filtering messages sent to the list. The lists themselves actually work the same way as the simple aliases from the last section. Each list has its own file to store list members, but rather than editing the file yourself, you can have the MLM automatically add and remove addresses.

The next two sections look at two popular MLMs: Majordomo and Mailman.

Majordomo

Majordomo is one of the more popular MLMs and has been available since the early 1990’s. It offers a complete set of MLM features, and nearly all administration takes place by sending commands through email messages. Little to no intervention is required by a postmaster once a list has been created. There are also web-based administration packages available to work with Majordomo, allowing much of the list administration to take place from a web site.

Majordomo is available at the Majordomo home page (http://www.greatcircle.com/majordomo/.) It requires Perl and works with Perl4 Version 4.036 or Perl5 Version 5.002 or better. Future releases will probably require Perl5. Majordomo also makes use of a small wrapper program written in C. If you are planning to build the package from scratch, you must have an ANSI C compiler.

If you configure Majordomo for moderated lists, where a list administrator approves posts using the Majordomo-supplied approve, you have to make an adjustment for Postfix and Majordomo to work together correctly. Postfix prepends a Delivered-To: header to messages it handles. It then uses the header to detect mailer loops. When a Majordomo message is delivered to a moderator for approval who then pipes the message through the approve command, it is sent back to the list with all of its original headers intact. When Postfix receives the message again, it recognizes that it has already seen the message and reports a mail delivery loop.

The easiest way to fix this issue is to make a small change to the Majordomo approve script (which is written in Perl). You’ll have to edit the file, normally located in the /bin directory located below the main Majordomo installation directory. If you follow the steps in the procedure below, your file will be located at /usr/local/majordomo/bin/approve. Edit the file and find the subroutine called process_bounce. Within that routine, there is a while loop, as shown below. Insert the emphasized line as shown, save the file, and you’re done:

while (<$FILE>) {
        if (/^>?From / && ! defined($from_skipped)) {
                # Skip any initial "From " or ">From " line
                $from_skipped = 1;
                next;
        }
        next if ( /^delivered-to:/i );  # Added for Postfix
        s/^~/~~/;
        print MAIL $_;
}

Creating a Majordomo list

The following steps walk you through setting up the astronomy list alias using Majordomo and Postfix. These instructions assume that you will create a user called majordom and install the package at /usr/local/majordomo. If you create a different username or install to a different location, keep that in mind as you read through this example.

  1. Make sure that you have Perl installed on your system and that it is at least Version 5.002 or better. You can check your Perl installation by typing perl -v at a command prompt. This will display license and other information about your installation of Perl, including the version number:

    $ perl -v
    This is perl, version 5.005_03 built for i386-freebsd
    Copyright 1987-1999, Larry Wall
    ...
  2. Obtain a copy of Majordomo either in source form from the Majordomo home page or find a prepackaged version from your normal software sources. Follow the instructions that come with your bundle to install Majordomo on your system. If you are installing from source, you will need an ANSI C compiler to build it.

    If you build Majordomo yourself, when you modify the Makefile and majordomo.cf file, you should be able to follow the instructions as if you were installing Majordomo to work with Sendmail as the MTA. If the location for $sendmail_command in majordomo.cf is correct, the rest of the mailer variables with the default options will be correct.

  3. Create and edit a file called /usr/local/majordomo/aliases to store the Majordomo aliases. Add the aliases for the Majordomo commands as specified in the Majordomo instructions. Then add the aliases for your list. The file should look like the following:

    majordomo:              "| /usr/local/majordomo/wrapper majordomo"
    owner-majordomo:        kdent@example.com
    majordomo-owner:        kdent@example.com
    # astronomy list
    astronomy:              :include:/usr/local/majordomo/lists/astronomy
    owner-astronomy:        csagan@example.com
    astronomy-request:      "|/usr/local/majordomo/wrapper request-answer astronomy"
    astronomy-approval:     csagan@example.com
  4. Edit /etc/postfix/main.cf to add the Majordomo alias file to the alias_maps parameter:

    alias_maps = hash:/etc/aliases, hash:/usr/local/majordomo/aliases
  5. You can also add the new alias file to the alias_database parameter to automatically rebuild the datafile when you run the newaliases command:

    alias_database = hash:/etc/aliases, hash:/usr/local/majordomo/aliases
  6. Reload Postfix so that it recognizes the changes in its main.cf configuration file:

    # postfix reload
  7. Create the file to hold the email addresses for the astronomy list. Set its ownership to the majordom account:

    # touch /usr/local/majordomo/lists/astronomy
    # chown majordom /usr/local/majordomo/lists/astronomy
  8. Create the info file that contains the message sent to new members of the list and anyone who sends the info command. Create the file as /usr/local/majordomo/lists/astronomy.info and include any text that is appropriate for your list:

    Welcome to the astronomy discussion list at example.com. The
    purpose of this list is to discuss new astronomical phenomena.
    To send a message to all the members of the list, address your
    email to <astronomy@example.com>.
    The basic rules and etiquette for the list are as follows:
    1. ...
  9. Make sure that the info file is accessible by the majordom account:

    # chown majordom /usr/local/majordomo/lists/astronomy.info
  10. Build the alias database:

    # postalias /usr/local/majordomo/aliases

Or, if you added the Majordomo alias file to alias_database, just type newaliases.

You can test your Majordomo installation by running the following command:

$ echo 'lists' | mail majordomo

Executing the above sends an email message to Majordomo containing the command ‘lists', telling Majordomo to send you information about all of the lists it maintains. On our example system, the reply from Majordomo looks like the following:

Date: Tue, 16 Jul 2002 18:14:59 -0400 (EDT)
From: Majordomo@example.com
To: kdent@example.com
Subject: Majordomo results

--

>>>> lists
Majordomo@example.com serves the following lists:

  astronomy               

Use the 'info <list>' command to get more information
about a specific list.
>>>> 
>>>>

You or your users can now send Majordomo commands at the address majordomo@example.com to get help and be added to lists. To add yourself to the new mailing list, send a message to majordomo with the subscribe command in the body of the message:

To: majordomo@example.com
From: tbrahe@porcupine.org
Subject:

subscribe astronomy

If you send a subscription request, you should receive a confirmation message from Majordomo. You must reply to the message with the authentication code provided to complete your subscription to the list (see the Majordomo documentation).

Potential problems

If you had no problems during the Majordomo installation, everything should work as expected. The main issue that you may run into has to do with file permissions. If you send a message to the list and receive a bounce notification like the following, then you know you have a permissions problem:

...
                        The Postfix program

<astronomy@example.com>: cannot open include file
    /usr/local/majordomo/lists/astronomy: Permission denied

...

Majordomo needs read access to the list file (/usr/local/majordomo/astronomy) and the list configuration file (/usr/local/majordomo/astronomy.config) when Postfix invokes it for deliveries to the list. Postfix delivers the message to Majordomo running with the privileges of the user that owns the alias map file containing the majordomo alias, /usr/local/majordomo/aliases.db. The normal mechanism used to ensure that Majordomo has access to the necessary files is to set the Majordomo wrapper program to set user ID (suid) with root as the owner. This means that regardless of the user executing the command, the process runs with root privileges. The Majordomo installation takes care of setting the permissions properly, but if for some reason they are not correct, you will see an error message like the one described above. You can correct the problem by setting the permissions yourself:

# chmod 4755 /usr/local/majordomo/wrapper

A better solution than setting the wrapper program suid is to make sure that the alias file and all of the list files are owned by the majordom user.

Mailman

Mailman is another full-featured MLM. It is available at the Mailman home page at http://www.gnu.org/software/mailman/. It includes web-based administration and creates a home page for each list where list administrators and members can perform administrative functions. It also accepts administrative commands via email much like Majordomo does.

Mailman requires at least Version 1.5.2 of Python. It includes some security wrapper programs that are written in C, so you must have an ANSI C compiler if you are planning to build the package from scratch.

There is one slightly tricky aspect to get Postfix and Mailman working together correctly. Mailman expects to be invoked by a process running with a particular group ID (GID). The GID it expects is specified at the time the Mailman package is built. If you are building the package yourself, make sure that you first create an account and a group called mailman . You should be able to use the normal administrative tools on your system to create both the account and the group. When you are finished, you should have an entry in /etc/passwd that resembles the following:

mailman:*:26413:60003:Mailman List Manager:/home/mailman:/bin/sh

and an entry in /etc/group like the following:

mailman:*:60003:

Make sure that the account mailman has the group mailman as its primary group. In the examples above, 60003 specifies the mailman group and the mailman account has that as its primary group.

When you run configure for Mailman, be sure that you include the option --with-mail-gid= xxx, where xxx is the actual GID for the mailman group that you created. According to the examples above, you should execute configure using 60003 for the GID option:

$ ./configure --with-mail-gid=60003

You may have additional options for configure according to your environment. Be sure to read the Mailman documentation for building the package. If you have already built your Mailman package and you did not specify the group, build it again. If you didn’t build your Mailman package, see the sidebar below.

Creating a Mailman list

The following steps walk you through setting up the astronomy list alias using Mailman and Postfix. They assume that you create an account and a group called mailman and install the package in /home/mailman.

  1. Make sure that you have Python installed on your system and that you have at least Version 1.5.2. Test this by executing the python command, which will display version information and a Python prompt. You can exit the Python shell by typing Ctrl-D:

    $ python
    Python 1.5.2 (#1, Jul  5 2001, 03:02:19)  [GCC...
    Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
    >>> ^D
    $

    If the version number following “Python” on the first line of output is not at least 1.5.2, you will have to upgrade your copy of Python.

  2. Obtain a copy of Mailman either in source form from the Mailman home page or find a prepackaged version from your normal software sources. Follow the instructions that come with your bundle to install Mailman on your system. If you are installing from source, you will need an ANSI C compiler to build it. Be sure to specify the correct GID when you build Mailman. (See the discussion earlier in this chapter.)

  3. You should create a separate alias file to store all of your Mailman aliases and set the owner and group correctly. Become the mailman user and execute the following commands. This example assumes that you want the alias file in the mailman home directory located at /home/mailman:

    $ cd /home/mailman
    $ touch aliases
    $ postalias aliases

    These commands create both the alias file and the necessary map files that Postfix uses for lookups. Since you perform these steps as the mailman user, the group and ownership of the files will automatically be correct, assuming your account is set up as it should be.

  4. Edit /etc/postfix/main.cf to add the new alias file for storing Mailman mailing lists. Simply add the Mailman alias file to the existing list of files for the alias_maps parameter:

    alias_maps = hash:/etc/aliases, hash:/home/mailman/aliases
  5. You can also add the new alias file to the alias_database parameter to automatically rebuild the datafile when you run the newaliases command:

    alias_database = hash:/etc/aliases, hash:/home/mailman/aliases
  6. Reload Postfix so that it recognizes the changes in its main.cf configuration file:

    # postfix reload
  7. Execute the Mailman command newlist to initialize your new mailing list. The output of newlist includes lines of text that must be inserted into the /home/mailman/aliases file. Copy the lines from the newlist output into /home/mailman/aliases. Save and exit the file. The emphasized lines in Example 10-4 are the lines that must be added to /home/mailman/aliases.

  8. Build the new alias datafile:

    # postalias /home/mailman/aliases

    Or, if you added the Mailman alias file to alias_database, just run the newaliases command.

Example 10-4. Executing the Mailman newlist command
# bin/newlist
Enter the name of the list: astronomy
Enter the email of the person running the list: kdent@example.com
Initial astronomy password:
Entry for aliases file:

## astronomy mailing list
                     ## created: 08-Mar-2002 root
                     astronomy:          "|/home/mailman/mail/wrapper post astronomy"
astronomy-admin:    "|/home/mailman/mail/wrapper mailowner astronomy"
astronomy-request:  "|/home/mailman/mail/wrapper mailcmd astronomy"
astronomy-owner:    astronomy-admin

Hit enter to continue with astronomy owner notification...

You or your users can now send requests to astronomy-request@example.com to get help and be added to the list. You can now use Mailman’s web- or email-based command interface to specify options for your new list. See the Mailman documentation to learn its options and other ways to work with the package.