Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Accessing properties from Outlook Addressbook

by tmetzger (Initiate)
on Apr 23, 2002 at 19:56 UTC ( [id://161415]=perlquestion: print w/replies, xml ) Need Help??

tmetzger has asked for the wisdom of the Perl Monks concerning the following question:

I am writing a Perl script where I need to pull an alias and an email address from the Outlook Addressbook. I was using the Outlook Object model but was not able to access the properties that I needed once I got to the Address Entry. Has anyone successfully used the CDO object model with Perl, or could you offer some alternatives on how I might accomplish this. I have searched all over for references but everything references VB. Thanks. Tim.
  • Comment on Accessing properties from Outlook Addressbook

Replies are listed 'Best First'.
(RhetTbull) Re: Accessing properties from Outlook Addressbook
by RhetTbull (Curate) on Apr 23, 2002 at 21:29 UTC
    Give this a try -- it works for me.
    #!/usr/bin/perl use strict; use warnings; use Win32::OLE; use Win32::OLE::Const 'Microsoft Outlook'; #what properties do we want to get from Outlook? my @properties = ( "Fullname", "PrimaryTelephoneNumber", "BusinessTelephoneNumber", "Business2TelephoneNumber", "BusinessFaxNumber", "HomeTelephoneNumber", "Home2TelephoneNumber", "MobileTelephoneNumber", "OtherFaxNumber", "OtherTelephoneNumber", "Email1Address", "Email1AddressType", "Email2Address", "Email2AddressType" ); #get an Outlook object my $outlook = Win32::OLE->new('Outlook.Application'); unless ($outlook) { my $error = Win32::OLE->LastError(); die "Couldn't start Outlook: $error"; } #get the Contacts folder my $namespace = $outlook->GetNamespace("MAPI"); my $folder = $namespace->GetDefaultFolder(olFolderContacts); my $items = $folder->Items; print "Folder: ", $folder->Name,"\n"; print "Total entries: ",$items->Count,"\n"; #print out the header print join(",",@properties),"\n"; #loop through the items, printing out each one foreach my $index (1..$items->Count) { my $contact = $items->item($index); my @entry; push @entry, $contact->{$_} foreach (@properties); print join(",",@entry),"\n"; };
    Note that the VB documentation is the best you'll get in most cases. Once you learn how Win32::OLE works though, you can usually reference the VB docs to figure out the object model then guess at what is needed to make it work with perl and Win32::OLE.
      What a good example! Thanks a lot -Percy

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-24 22:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found