Mailing List CGatePro@mail.stalker.com Message #102768
From: Brian Gibson <gibson_brian@wheatoncollege.edu>
Subject: Re: group member export
Date: Mon, 05 Dec 2011 09:14:13 -0500
To: CommuniGate Pro Discussions <CGatePro@mail.stalker.com>
This perl script uses the CLI.pm perl module to talk to the mail server and get all of the groups for a specific domain and print out all the email addresses in the group

#!/usr/bin/perl


use CLI;  ## Load the CGPro perl module needed to talk to the server

## Here we open up the results file.

open(RESULTS,">group_membership.txt");


$CGServerAddress = "<your servers IP address>";
$PostmasterLogin = "postmaster\@<YOUR DOMAIN>";
$PostmasterPassword = "<Your postmaster password>";
$domain_with_groups = "<YOUR DOMAIN>";

## Here we initialize a CGP object so we can work with the server.
my $cli = new CGP::CLI( { PeerAddr => $CGServerAddress,
                            PeerPort => 106,
                            login    => $PostmasterLogin,
                            password => $PostmasterPassword } );





## Now we use the "CLI" perl module to get a listing of all the lists
## on the server.

if($Groups=$cli->ListGroups($domain_with_groups)) {
   
    print "The groups are:\n";

    foreach (@$Groups) {

        ## Just to be safe we make the group name lowercase and
        ## add it to an array

        $lc_groupname = lc($_);

        print "\t$lc_groupname\n";

        push(@array_of_groups,$_);

    }

} else {
   
    ($cli->isSuccess) ? print "No groups.\n"
                      : die "Error: ".$cli->getErrMessage.", quitting";
}


## Now we go through each group and get the subscribers

foreach $groupname (@array_of_groups) {

    print "*$groupname*\n";

    print RESULTS "$groupname:";

    print "\tGetting addresses in group\n";

    if($Settings=$cli->GetGroup($groupname)) {
            print "The settings are:\n";
            foreach (keys %$Settings) {
                  my $data=@$Settings{$_};
                  print "  $_ = ";
                  if(ref ($data) eq 'ARRAY') {
                    foreach my $member (@$data) {
                          print "\'$member\' ";
                    $lowercase_email_address = lc($member);

                    ## If the email address is not fully qualified add @<YOUR DOMAIN> to the end

                    if ($lowercase_email_address !~ /\@/) {

                        $lowercase_email_address = $lowercase_email_address . "\@" . $domain_with_groups;
               
                    }

                    print RESULTS "$lowercase_email_address,";
                    }
                    print "\n";
                  } else {
                    print "\"$data\"\n";
                  }
            }
      } else {
            die "Error: ".$cli->getErrMessage.", quitting";
      }


    print RESULTS ":\n";

}

close RESULTS;

$cli->Logout;



On 12/4/2011 11:53 PM, Agi Subagio wrote:
sorry for asking this, i can't find the answer in the mailing list archive.

how to export list of member from a group in cgp into excel or csv?


#############################################################
This message is sent to you because you are subscribed to
 the mailing list <CGatePro@mail.stalker.com>.
To unsubscribe, E-mail to: <CGatePro-off@mail.stalker.com>
To switch to the DIGEST mode, E-mail to <CGatePro-digest@mail.stalker.com>
To switch to the INDEX mode, E-mail to <CGatePro-index@mail.stalker.com>
Send administrative queries to  <CGatePro-request@mail.stalker.com>

--

++++++++++++++++++++++++++++
Brian Gibson
Systems Administrator
Wheaton College

Are you a musician? If so visit my Arbans Online music site at http://arbansonline.com and listen & contribute
Subscribe (FEED) Subscribe (DIGEST) Subscribe (INDEX) Unsubscribe Mail to Listmaster