Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Win32::OLE & Outlook getting the actual email addresses

by cormanaz (Deacon)
on Jul 27, 2008 at 18:47 UTC ( [id://700409]=note: print w/replies, xml ) Need Help??


in reply to Win32::OLE & Outlook getting the actual email addresses

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"; } }

Replies are listed 'Best First'.
Re^2: Win32::OLE & Outlook getting the actual email addresses
by Latha sree (Initiate) on Nov 25, 2011 at 09:41 UTC

    Hi, How to get the Sender Email Address for the same code with out using the "Redemption.MAPIFolder" module. Thanks in Advance. Regards, Latha Sree

      You lookup the object reference msdn and use the appropriate method (I guess ->Sender)

        Can you elaborate the information which you provided as I am not able to understand what to use.

Log In?
Username:
Password:

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

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

    No recent polls found