Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Adding a list of contacts to Exchange Address book.

by SquireJames (Monk)
on Dec 11, 2003 at 01:12 UTC ( [id://313942]=note: print w/replies, xml ) Need Help??


in reply to Adding a list of contacts to Exchange Address book.

I haven't done exactly what you're looking for, but I do a lot of stuff with Active Directory by using Net::LDAP and Win32::OLE. Net::LDAP is probably a bit easier to use, whilst Win32::OLE allows you to do some stuff without authenticating (allowing pass through, if you will).

An excellent resource for this type of stuff is the book "Managing Enterprise Active Directory Services" by Robbie Allan and Rickard Puckett, which contains examples of anything that you'd want to do in both VB and Perl.

I haven't creatd contact objects, only user ones, but I think that what I've suplied you with below should work.

use strict; use Net::LDAP; use Net::LDAP::Entry; my $ldap_prov = *servername* print ("\nUsername for connection: "); my $username = <STDIN>; print ("\nPassword: "); my $password = <STDIN>; chomp $username; chomp $password; my $ldap = Net::LDAP->new($ldap_prov) || die; my $bind = $ldap->bind($user, password => $password, $version => 3); my $contact = Net::LDAP::Entry->new(); $contact->dn("cn=$contact,cn=contacts,dc=aaa,dc=com); $contact->add(objectclass -> 'contact'); # I'm not sure if you'll need + to pass anything else here. Normally when you setup a user, you'll +need to also pass the SAMAccountName attribute.... my $result = $contact->update($ldap); $ldap->unbind;
This (should) create the contact, although it may take some fiddling to get spot on. I've only ever used it to create users, but theoretically speaking it should be fine for contacts. Let me know how you go with it if you choose to try and code it.

Obviously before you unbind and after you update, you could add any further fields that you want to, or you could just add more attributes during the initial create.

Replies are listed 'Best First'.
Re: Re: Adding a list of contacts to Exchange Address book.
by thunders (Priest) on Dec 11, 2003 at 16:49 UTC
    Thanks that code works perfectly, I tested it with the following and it created my contact, "SAMAccountName" isn't a required field for contacts, all they really seem to need is the "dn" and "objectClass" fields.
    use strict; use Net::LDAP; use Net::LDAP::Entry; my $ldap_prov = "server"; my $ldap = Net::LDAP->new($ldap_prov) || die; print ("\nUsername for connection: "); my $username = <STDIN>; print ("\nPassword: "); my $password = <STDIN>; chomp $username; chomp $password; my $bind = $ldap->bind($user, password => $password, $version => 3); my $contact = Net::LDAP::Entry->new(); my $name = "Bob Smith"; my $email = 'bobs@website.com'; $contact->dn( "cn=$name,ou=Website External Contacts," ."dc=corp,dc=website,dc=com" ); $contact->add(objectClass => 'contact'); $contact->add(name => $name); $contact->add(displayName => $name); $contact->add(mail => $email); $contact->add(targetAddress => "SMTP:$email"); my $result = $contact->update($ldap); $ldap->unbind;
      sorry i'm not a script person. there might be something that i'm missing there. it looks like that you are still importing one contact at a time, and need to fill in those names and email address in the script one by one. How then can I do the bulk of a thousand at one go, if their names and email addresses are already in an excel file?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://313942]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (6)
As of 2024-03-28 10:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found