If Outlook is available you may be better off using that.
This is a skeleton of something I've used. You'd need to adjust the mailbox name.
#!/usr/bin/perl
use v5.12.2;
use warnings;
use strict;
use Win32::OLE;
my $mail = parse_inbox();
sub parse_inbox{
# use existing instance if Outlook is already running, or launce a n
+ew one
my $ol;
eval {$ol = Win32::OLE->GetActiveObject('Outlook.Application')};
die "Outlook not installed" if $@;
unless (defined $ol) {
$ol = Win32::OLE->new('Outlook.Application', sub {$_[0]->Quit;})
or die "Oops, cannot start Outlook";
}
my $mailbox = seekFolder(
$ol->Session,
'Mailbox - John Sharpe'
); # adjust to suit
my $folder = seekFolder(
$mailbox,
'Inbox'
);
my (%table);
for (my $i = 1; $i <= $folder->Items->Count; $i++) {
my $sender_name = $folder->Items->Item($i)->SenderName;
my $subject = $folder->Items->Item($i)->Subject;
my $body = $folder->Items->Item($i)->Body;
say $subject;
# process
# store something in table
}
return \%table;
}
sub seekFolder {
my $obj = shift;
my $target = shift;
for (my $i = 1; $i <= $obj->Folders->Count; $i++) {
if ($obj->Folders->Item($i)->Name eq $target) {
return $obj->Folders->Item($i);
}
}
return;
}
Tested with Outlook 2003. There is a snag in that after the script is started Outlook complains that something is trying to look at the contact list. You need to click a checkbox and OK.
-
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.
|