How to get a .csv of subscribers on all your Mailman lists

Posted by – May 16, 2009

The boss asked me to create a list of everyone subscribed to every discussion list we have. Ended up being like 3000 lines…luckly there is a python script that polls the mailman admin web interface. The below script makes it quite a bit easier to perform on all the lists.

First thing, you need a file with all of your list names – this works:

ls /usr/local/mailman/lists | cat > lists.txt ## This is where mailman is located on FreeBSD

Next, download mailman-subscribers.py to your home directory.

Finally, you need to create a shell script (i.e. getallsubscribers.sh) and paste the following (substitute the [[bracketed text]] with the info for your system):

while read line
do
 echo $line | cat >> listsAndMembers.csv
  ~/mailman-subscribers.py -c [[your.mailman.host]] $line [[listAdminPassword]] | cat >> listsAndMembers.csv
  echo | cat >> listsAndMembers.csv
  echo | cat >> listsAndMembers.csv
done < lists.txt

Now make the file executable and run it:
chmod +x getallsubscribers.sh
./getallsubscribers.sh

That's it. You should have a single file with all of your lists and their subscribers.

edit: It came up later that it would be nice to get a list of who from each domain was subscribed. This regex will turn up the listname and name/email for each subscriber in the .csv

(?:.*(?:gmail\.com)"|^[^"].*$)

10 Comments on How to get a .csv of subscribers on all your Mailman lists

  1. Bret Miller says:

    Awesome! Just what I was looking for. Thanks!

  2. Justin says:

    My pleasure!

  3. robert schwartz says:

    How do you get a list of users if you are running in windows xp?

  4. Nancy says:

    @robert

    If you install Cygwin on your Windows XP system (see cygwin.com) you’ll have all that you need (including Python) to run the scripts above. [I just discovered this -- won't tell you how long I've been looking for something I could script locally. Thanks, folks.]

  5. Him Bahadur Shah says:

    I was looking for. Thanks

  6. Snaky says:

    Hi, will this export ALL member info that is available in mailman?
    And can this be useful in importing all the members back into a fresh mailman install – with all member attributes?

  7. Ken Williams says:

    One small nit – way too many cats. All your cats can just be removed.

    For example, “ls /usr/local/mailman/lists | cat > lists.txt” is exactly equivalent to “ls /usr/local/mailman/lists > lists.txt”.

  8. Justin says:

    @Ken You’re right

  9. ouvrir says:

    How can i do the opposite?
    i mean i have a csv file which contains a list of members, i want to put all members in my mailing list using cli.
    any idea?
    thanx

  10. Justin says:

    Have a look at Mailmans bin directory. On Debian it’s at /usr/lib/mailman/bin.

    You’ll want to use the add_members script to do what you need. Note that your csv needs to be of the format:

    "Firstname Lastname" email@example.com

    
    $ /usr/lib/mailman/bin/add_members -h
    
    /usr/lib/mailman/bin/add_members
    Add members to a list from the command line.
    
    Usage:
        add_members [options] listname
    
    Options:
    
        --regular-members-file=file
        -r file
            A file containing addresses of the members to be added, one
            address per line.  This list of people become non-digest
            members.  If file is `-', read addresses from stdin.  Note that
            -n/--non-digest-members-file are deprecated synonyms for this option.
    
        --digest-members-file=file
        -d file
            Similar to above, but these people become digest members.
    
        --welcome-msg=<y|n>
        -w <y|n>
            Set whether or not to send the list members a welcome message,
            overriding whatever the list's `send_welcome_msg' setting is.
    
        --admin-notify=<y|n>
        -a <y|n>
            Set whether or not to send the list administrators a notification on
            the success/failure of these subscriptions, overriding whatever the
            list's `admin_notify_mchanges' setting is.
    
        --help
        -h
            Print this help message and exit.
    
        listname
            The name of the Mailman list you are adding members to.  It must
            already exist.
    
    You must supply at least one of -r and -d options.  At most one of the
    files can be `-'.
    

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">