<?xml version="1.0" encoding="windows-1252"?>
<node id="61803" title="Extract Outlook Telephone Numbers" created="2001-03-02 14:10:55" updated="2005-08-11 06:29:18">
<type id="1748">
sourcecode</type>
<author id="5348">
Corion</author>
<data>
<field name="doctext">
&lt;code&gt;
#!/usr/bin/perl -w

use strict;
use Win32::OLE;

my @PhoneProperties = (
  "Business2TelephoneNumber",
  "BusinessFaxNumber",
  "BusinessTelephoneNumber",
  "CarTelephoneNumber",
  "Home2TelephoneNumber",
  "HomeTelephoneNumber",
  "ISDNNumber",
  "MobileTelephoneNumber",
  "OtherFaxNumber",
  "OtherTelephoneNumber",
  "PrimaryTelephoneNumber",
);

my $outlook;
$outlook = Win32::OLE-&gt;new('Outlook.Application');

my $activeexplorer;
$activeexplorer = $outlook-&gt;ActiveExplorer;

print $activeexplorer-&gt;Caption,"\n";

my $items = $activeexplorer-&gt;CurrentFolder-&gt;Items;
print $items-&gt;Count,"\n";

my $linenumber = 1;
print "NR;NAME;TELNUM\n";

my $Kontakt;
my $PhoneProp;
my $ItemIndex = 1;

while ($ItemIndex &lt;= $items-&gt;Count) {
  $Kontakt = $items-&gt;item($ItemIndex);

  foreach $PhoneProp (@PhoneProperties) {
    my $number = $Kontakt-&gt;{"$PhoneProp"};
    if ($number) {
      # Prefix local area code unless an area code
      # is already given
      if ($number !~ /^0/) { $number = "069$number" };
      $number =~ s/ +//g;
      $number =~ s/-+//g;
      print $linenumber++, ";", $Kontakt-&gt;FullName,";'$number\n";
      #print "$number=", substr( $Kontakt-&gt;FullName, 1, 15 ),"\n";
    };
  };

  $ItemIndex++;
};
&lt;/code&gt;</field>
<field name="codedescription">
This is a small example on how to use the MS Outlook object model from within Perl (under Win32 of course) to extract contacts data. If you have the Outlook object model chart at hand, it's easy to automate other tasks such as sending mail or creating contacs as well. This snippet needs Outlook to be open and the Contacts view must be active, because I was too lazy to drill my way down from Outlook-&gt;Application to the Contacts view.

&lt;p&gt;&lt;b&gt;Update:&lt;/b&gt;I added the missing &amp;lt;code&amp;gt; tags myself. Even more stupid I am ...
&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Update 2:&lt;/b&gt;Some documentation - the &lt;tt&gt;069&lt;/tt&gt; is my local area code.&lt;/p&gt;
</field>
<field name="codecategory">
Win32 Stuff; OLE Automation</field>
<field name="codeauthor">
Max Maischein (Corion) corion@informatik.uni-frankfurt.de</field>
</data>
</node>
