Win32::OLE works great for accessing Outlook from Perl, with the below iterating over all the messages in your Inbox (but possibly not sub-folders).
#!perl
use strict;
use warnings;
use Win32::OLE 'in';
use Win32::OLE::Const 'Microsoft Outlook'; # olFolderInbox
my $outlook = Win32::OLE->GetActiveObject('Outlook.Application')
or do {
my $reason = Win32::FormatMessage(Win32::GetLastError());
die "Cannot get active Outlook object: $reason";
};
my $namespace = $outlook->GetNamespace('MAPI');
if (my $folder = $namespace->GetDefaultFolder(olFolderInbox)) {
print $folder->Name, "\n";
foreach my $email (in $folder->Items) {
print " ", $email->Subject, "\n"
if $email->Subject eq 'Build 50.2';
# Do something with $email.
}
}
However, if you do plan on doing something further with $email once you've found the right message, it is essential that you use ActivePerl's OLE browser, thumb through the MSDN Library and/or Google liberally for example usage as knowing what to access or look for in the OLE objects is 99% of the battle!
Update: s/ eq /\n if $email->Subject eq /; # oops
-
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.
|