Results 1 to 2 of 2

Thread: Auto create a distribution list with all accounts in the server

  1. #1
    Join Date
    Nov 2011
    Location
    Hungary
    Posts
    30
    Rep Power
    4

    Default Auto create a distribution list with all accounts in the server

    Hi guys!

    I always have a problem when i need to send a global announce to all users in the zimbra. Using the command line all the time is not to user friendly, creating a contact group or distribution list is much better idea, but if any new user will be added to the system, it will be missing form this list. So i come up with an automated solution.
    This method periodically recreate a distribution list with all active email account except what is not a usual account like virus, spam, ham, abuse etc...

    Step1: You need to activate the Milter server if not activated already.
    This step is already described well in this page.

    Step2: Once you have up and running Milter server you can continue with this step:
    You need to define where is your 'zmaccts' zimbra binary (usually at /opt/zimbra/bin)
    Be careful, zmaccts email field size is limited to 36 character, so if you have a longer email address you need to patch this file first (or copy to a new one zmaccts2 and use that)

    In zimbra 6.x 7.x:
    Code:
    --- /opt/zimbra/bin/zmaccts     2012-08-16 06:30:32.000000000 +0200
    +++ /opt/zimbra/bin/zmaccts2    2012-10-09 18:54:02.876922128 +0200
    @@ -84,7 +84,7 @@
     .
     
     format ACCOUNT = 
    -@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<   @>>>>>>>>>>     @>>>>>>>>>>>>>>  @>>>>>>>>>>>>>>
    +@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<   @>>>>>>>>>>     @>>>>>>>>>>>>>>  @>>>>>>>>>>>>>>
     $name, $status, $created, $logon
     .
     
    @@ -134,7 +134,7 @@
     .
     
     format DOMAIN =
    -@<<<<<<<<<<<<<<<<<<<<<<   @>>>>>>>  @>>>>>>>  @>>>>>>>  @>>>>>>>>>>>>  @>>>>>>>
    +@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<   @>>>>>>>  @>>>>>>>  @>>>>>>>  @>>>>>>>>>>>>  @>>>>>>>
     $domainName, $numActive, $numClosed, $numLocked, $numMaint, $numTotal
     .
    In zimbra 8.x:
    Code:
    --- /opt/zimbra/bin/zmaccts     2012-09-08 00:05:42.000000000 +0200
    +++ /opt/zimbra/bin/zmaccts2    2012-10-09 16:06:35.594994816 +0200
    @@ -138,7 +138,7 @@
     # generate reports...
     
     # column widths and separators
    -my @w = ( 36, 11, 15, 15 );
    +my @w = ( 72, 11, 15, 15 );
     my @s = ( map( " " x $_, 3, 5, 2 ), "\n" );
     
     # col 0 left aligned, others right aligned, all strings truncate at max length
    If you have the extended field size you can use this binary in this script (called collectusers.sh):

    Usage: collectusers.sh listname@domain.tld adminemail@domain.tl
    listname@domain.tld: your distribution list name
    adminemail@domain.tld: because this list contain all users in this server sending email to the list permitted only from this address (safety reason)

    Run with zimbra user!

    Code:
    #!/bin/bash
    
    # Zimbra binary
    zmaccts="/opt/zimbra/bin/zmaccts2"
    
    listname=$1
    admin=$2
    
    echo "Auto create a distribution list with all email account for bulk email sending"
    
    if [ -z $1 -o -z  $2 ]; then
        echo -e "\nMissing a required parameter."
        echo "Usage: collectusers.sh listname@domain.tld adminemail@domain.tld"
        exit 0
    fi
    
    alluser=`$zmaccts | grep 'active' | egrep -v '^\W+|virus|galsync|ham|spam|abuse' | awk '{print $1}' | sort | tr '\n' ' '`
    
    echo -en "\nRemoving old list if exsist..."
    zmprov ddl $listname > /dev/null 2>&1
    echo "Done"
    echo -n "Creating distribution list: $listname..."
    zmprov cdl $listname > /dev/null 2>&1
    echo "Done"
    echo $alluser | tr ' ' '\n' | sort > userlist.txt
    echo "Userlist saved to: userlist.txt"
    zmprov adlm $listname $alluser > /dev/null 2>&1
    echo -n "Fill list $listname with users..."
    echo "Done"
    zmprov grr dl $listname usr $admin sendToDistList > /dev/null 2>&1
    echo -e "Only $admin can send email to this list!\n"
    echo "Restarting services:"
    zmmtactl restart
    
    exit 0
    Step3:
    Edit zimbra crontab:
    crontab -e -u zimbra

    Append this to the end of the file (make sure that you have a newline at the end!) (edit the script location and the parameters):
    0 6 * * * /your/script/patch/collectusers.sh listname@domain.tld adminemail@domain.tld

    Step4:
    Restart crontab

  2. #2
    Join Date
    Mar 2012
    Posts
    19
    Rep Power
    3

    Default

    dunno why no one complemented you on your post. Good job sir!

Similar Threads

  1. Auto-reply for distribution list
    By shanson in forum Administrators
    Replies: 5
    Last Post: 02-22-2013, 01:30 PM
  2. Auto Create Accounts
    By mudgey in forum Users
    Replies: 1
    Last Post: 03-14-2012, 05:35 PM
  3. Create account and add to distribution list?
    By blazeking in forum Administrators
    Replies: 1
    Last Post: 09-08-2011, 08:15 PM
  4. Auto add new accounts in distribution list?
    By mrjohnsen in forum Administrators
    Replies: 0
    Last Post: 08-25-2011, 12:35 AM
  5. Replies: 2
    Last Post: 10-14-2009, 12:08 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •