Any time you have an Outlook item open in a separate window, it's in an Inspector.
What I would do in this case is get the list of all the Inspectors, filter out the ones that aren't open on a Mail item, and then, if necessary, apply further filtering on the contents of the item. For example:
use Win32::OLE;
use Win32::OLE::Const '.*Outlook'; # load the relevant constants
my $ol = new Win32::OLE 'Outlook.Application';
my $inspectors = $ol->Inspectors;
my @inspectors = Win32::OLE::Enum->new( $inspectors )->All;
my @mail_items =
grep { $_->Class == olMail }
map { $_->CurrentItem } # get the MailItem object
@inspectors;
You could, perhaps, try to rely on the fact that for a brand spanking new mail message, the Inspector has a caption (that is, its window has a title)
of Untitled - Message (Plain Text)
my @mail_items =
grep { $_->Class == olMail }
map { $_->CurrentItem } # get the MailItem object
grep { $_->Caption eq 'Untitled - Message (Plain Text)' }
@inspectors;
Once you've found the element in @mail_items which is the one you want, you can extract its body text with the Body method, of course.
jdporter The 6th Rule of Perl Club is -- There is no Rule #6. | [reply] [d/l] [select] |