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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-26 03:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found