I used the following snippet to create contacts in a script that
synced the GAL with a file that got dumped by the sendmail smarthost
every night, creating contacts for new email addys, and removing
contacts that were not in the new file dump.

The script is done in perl ...

# Add the Contacts that are new to the company
$ctacount = 0;
foreach $CTA (@ContactsToAdd) {
        # Build the mailvar variable.
        @name = split(/ /,$CTA);
        $mailvar = "[EMAIL PROTECTED]";
        # Open the process for creating the Contact.
        my $NewContainer =
Win32::OLE->GetObject("LDAP://ou=Contacts,dc=domain,dc=local";);
        my $NewContact = $NewContainer->Create("contact","CN=$name[0]
$name[1]");
        $NewContact->Put("givenName",$name[0]);                       
 # First Name
        $NewContact->Put("sn",$name[1]);                              
 # Last Name
        $NewContact->Put("displayname","$name[0] $name[1]");    # Display Name
        $NewContact->Put("mail",$mailvar);                            
 # Mail value
        $NewContact->Put("targetAddress","SMTP:".$mailvar);     # Primary SMTP
        $NewContact->Put("mailnickname","$name[0] $name[1]");   # Alias
        # The targetAddress and mailnickname attributes _must_ be populated
        # in order for the contact to show up in the Exchange2k default GAL.
        $NewContact->SetInfo;   # Finalize the object creation.
        print CALOG "Contact Added to Directory => $name[0] $name[1]\n";
        $ctacount++;
}

close CALOG;
List info   : http://www.activedir.org/mail_list.htm
List FAQ    : http://www.activedir.org/list_faq.htm
List archive: http://www.mail-archive.com/activedir%40mail.activedir.org/

Reply via email to