Well boys and girls, I spent my Saturday and Sunday morning looking into this problem some more. I sure know how to have a good time, don't I?

My research indicates that all the cool kids are using an API called Redemption to talk to Outlook. There are lots of good reasons for this that you can read about on their web page. But for the purposes of this thread it gives you an easy (well, OK, not exactly easy but manageable) way to resist Microsoft hegemony by getting SMTP addresses when Outlook decides that what you really should want is one of its X400 addresses.

So here for your computing enjoyment is some code that uses Redemption to go through your inbox and enumerate the sender and recipients' SMTP addresses.

Steve

#!/usr/bin/perl -w use strict; use Win32::OLE; use Win32::OLE::Variant; use Win32::OLE::Const 'Microsoft Outlook'; # set up Outlook OLE my $Outlook; eval {$Outlook = Win32::OLE->GetActiveObject('Outlook.Application')}; die "Outlook not installed" if $@; unless (defined $Outlook) { $Outlook = Win32::OLE->new('Outlook.Application', sub {$_[0]->Quit +;}) or die "Can't start Outlook: $!"; } my $ol = Win32::OLE::Const->Load($Outlook); my $namespace = $Outlook->GetNamespace("MAPI"); # select mailbox and folder my $mailboxname = "myMailbox"; # change this to the actual name of you +r mailbox my $foldername = 'Inbox'; # or whatever other folder you want to use my $ofolder = $namespace->Folders($mailboxname)->Folders($foldername) +|| die "Can't open folder Inbox: $!\n"; my $sfolder = new Win32::OLE("Redemption.MAPIFolder"); $sfolder->{'Item'} = $ofolder; # process messages my $n = $sfolder->Items->Count; my $sitem = new Win32::OLE("Redemption.SafeMailItem"); for (my $i=$n; $i>0; $i--) { $sitem->{'Item'} = $sfolder->Items($i); print "Subject: ",$sitem->{'Subject'},"\n"; # show sender as insured SMTP address my $sendaddrtype = $sitem->Fields(0xC1E001E); # hex key for SENDER +_ADDRTYPE my $senderemail; if ($sendaddrtype eq 'EX') { $senderemail = $sitem->{'Sender'}->Fields(0x39FE001E); # hex k +ey for EMAIL } else { $senderemail = $sitem->{'SenderEmailAddress'}; } print "\tSender: $senderemail\n"; # show recipients' SMTP addresses my $nrecip = $sitem->Recipients->Count; for my $j (1..$nrecip) { print "\tRecipient $j: ",$sitem->Recipients($j)->AddressEntry- +>SMTPAddress,"\n"; } }

In reply to Re: Win32::OLE & Outlook getting the actual email addresses by cormanaz
in thread Win32::OLE & Outlook getting the actual email addresses by cormanaz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.