Mailman with Postfix and Nginx on CentOS 6

Fri, Feb 24, 2012 2-minute read

In this tutorial I will show you how to set up Mailman with Postfix and Nginx on CentOS 6. I assume you have already set up Nginx to server CGI scripts using fcgiwrap like I’ve shown you in the previous post.

Here is the link: http://black-pixel.net/serving-cgi-scripts-with-nginx-on-centos-6.html

I also presuppose that you have a working Postfix configuration.

 

The first step is to install Mailman.

yum install mailman

Next you have to edit your /usr/lib/mailman/Mailman/Defaults.py and change the DEFAULT_URL_PATTERN.

DEFAULT_URL_PATTERN = 'http://%s/mailman/cgi-bin/'

This is the same hierarchy as in the directory at /usr/lib.

Next download this script: http://black-pixel.net/stuff/postfix-to-mailman.tar

Extract the postfix-to-mailman.py into the folder /usr/lib/mailman/bin/.

 

 

As a next step, you’ll have to create a Nginx configuration.

vim /etc/nginx/conf.d/lists.example.conf

Add the following lines and adjust you domain:

server {
    server_name  lists.exmaple.com;                   # your domain name

        location /mailman/cgi-bin {
               root /usr/lib;
               fastcgi_split_path_info (^/mailman/cgi-bin/[^/]*)(.*)$;
               include /etc/nginx/fastcgi_params;
               fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
               fastcgi_param PATH_INFO $fastcgi_path_info;
               fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
               fastcgi_intercept_errors on;
               fastcgi_pass unix:/var/run/fcgiwrap.socket;
        }

        location /images/mailman {
               alias /usr/share/images/mailman;
        }

        location /pipermail {
               alias /var/lib/mailman/archives/public;
               autoindex on;
        }
}

That’s it for Nginx, don’t forget to restart it.

 

The last thing we have to take care of is the Postfix configuration.

postconf -e 'relay_domains = lists.example.com'
postconf -e 'mailman_destination_recipient_limit = 1'

Make sure your local IPv6 adress is at mydestinations = in your main.cf because mailman seems to use it for sending mails.

mydestinations = 127.0.0.1/8, [::1]/128

 

Next edit the master.cf file and add the following to the bottom:

mailman   unix  -       n       n       -       -       pipe
  flags=FR user=list(i used mailman) argv=/usr/lib/mailman/bin/postfix-to-mailman.py
  ${nexthop} ${user}

Now we need a transport map:

postconf -e 'transport_maps = hash:/etc/postfix/transport'

Edit the new transport file and add the following line:

lists.example.com mailman:

After that:

postmap -v /etc/postfix/transport
service postfix restart

You’re nearly done, add the defaul mailing list called mailman:

/usr/lib/mailman/bin/newlist --urlhost=lists.example.com --emailhost=lists.example.com mailman

Edit your aliases file as told and execute newaliases and postfix restart.

Now you can do the same for any mailing list you want to create.

After that start Mailman and add it to chkconfig.

service mailman start
chkconfig -–levels 2345 mailman on

You can access the Mailman list page at lists.example.com/mailman/cgi-bin/listinfo.

 

If you have any problems feel free to write a comment and I will try to help you asap. I’m not 100 percent sure if I’ve written everything necessary as I had to tweak around a lot to make it work.