In this post, I describe how to install and configure mailman for a virtual host on a Debian Jessie server using Apache, Postfix and SpamAssassin. Instructions on how to do this are in various places on the internet, but I didn’t find anywhere that collected all the different pieces together. These instructions should also work for Ubuntu.
PrerequisitesBefore starting, you’ll need to install Apache, Postfix and SpamAssassin. As this post is focused on Mailman I won’t talk about how to set up Apache, Postfix or SpamAssassin, as there are already plenty of good guides out there explaining how to configure them. I’ll only mention the changes required to their configuration for them to work with Mailman. Throughout this guide, I'll assume that you’re setting up Mailman on the domain example.com.
Install MailmanOnce Apache, Postfix and SpamAssassin are all set up and working, install Mailman with
apt-get install mailman.
Configure ApacheNext, edit the Apache config for your site. In the
<VirtualHost>section belonging to example.com, add the following lines:
# We can find mailman here: ScriptAlias /cgi-bin/mailman/ /usr/lib/cgi-bin/mailman/ # And the public archives: Alias /pipermail/ /var/lib/mailman/archives/public/ # Logos: Alias /images/mailman/ /usr/share/images/mailman/ <Directory /usr/lib/cgi-bin/mailman/> AllowOverride None Options ExecCGI AddHandler cgi-script .cgi Require all granted </Directory> <Directory /var/lib/mailman/archives/public/> Options FollowSymlinks AllowOverride None Require all granted </Directory> <Directory /usr/share/images/mailman/> AllowOverride None Require all granted </Directory>Check that the new Apache config is valid using
apache2ctl configtest. Assuming there are no errors, you can then tell Apache to pick up the new config with
systemctl reload apache2.
Configure MailmanNow create the default
mailmanmailing list. This is required before you can set up your own lists. The command is
newlist --urlhost=example.com --emailhost=example.com mailman. Replace both instances of
example.comwith your domain name. Next, edit the Mailman config to tell it to use Postfix and SpamAssassin. Open
/etc/mailman/mm_cfg.pyand add the following lines:
MTA='Postfix' SPAMD_HOST = 'localhost' DISCARD_SCORE = 8 HOLD_SCORE = 4 MEMBER_BONUS = 0 POSTFIX_STYLE_VIRTUAL_DOMAINS = ['example.com']You can adjust the
MEMBER_BONUSas you prefer. Once that’s done, run
service mailman restart. Then generate the mail aliases files with the command
/usr/lib/mailman/bin/genaliases. This will automatically be kept up to date by Mailman when you add further mailing lists, but you need to manually generate it the first time.
DKIM considerationsYou will probably want to add
REMOVE_DKIM_HEADERS = Yesto
/etc/mailman/mm_cfg.py. If you don’t, mail from domains that sign their messages using DKIM (this includes pretty much all major providers, including Gmail) are likely not to reach recipients’ inboxes due to spam filtering. The changes that Mailman makes to the message body before sending it on tend to invalidate the DKIM signature, but by default Mailman leaves DKIM headers intact even though they are no longer valid.
/etc/postfix/main.cfand put in the lines below. Most if not all of these lines should already be there. The key points are:
alias_databaseshould NOT include the Mailman aliases file.
alias_mapsmust include the Mailman aliases file.
virtual_alias_domainsmust include the domain(s) for your email lists, as well as any other active virtual domains (the sample config below includes example.net as an active virtual mail domain that isn’t used by Mailman).
virtual_alias_mapsmust include the Mailman virtual alias file.
alias_database = hash:/etc/aliases alias_maps = hash:/etc/aliases, hash:/var/lib/mailman/data/aliases virtual_alias_domains = example.com example.net virtual_alias_maps = hash:/etc/postfix/virtual, hash:/var/lib/mailman/data/virtual-mailman
TestNow you’re ready to test. Create a test mailing list with
newlist --urlhost=example.com --emailhost=example.com test. Open http://example.com/cgi-bin/mailman/listinfo/test in your browser, and you should see the mailing list’s information page. Subscribe to the list and try sending a test message to email@example.com. If it didn’t work, check your logs:
/var/log/mail.logfor Postfix, and
/var/log/mailman/errorfor Mailman. Try sending a regular message to make sure that it gets through, and a message including the GTUBE to make sure that spam is being filtered correctly.
Add Mailman cron jobsFinally, set up cron jobs so that Mailman automatically does regular housekeeping by running the command
crontab -u list /var/lib/mailman/cron/crontab.in.