20080530 list messages in an outlook folder - plembo/onemoretech GitHub Wiki

title: List messages in an Outlook folder link: https://onemoretech.wordpress.com/2008/05/30/list-messages-in-an-outlook-folder/ author: lembobro description: post_id: 517 created: 2008/05/30 19:54:10 created_gmt: 2008/05/30 19:54:10 comment_status: open post_name: list-messages-in-an-outlook-folder status: publish post_type: post

List messages in an Outlook folder

Needed to get the headers from a bunch of spam I’ve received over the last couple of days. So I started to research what it would take to query my Outlook client using perl. Although I’m not quite there yet, I have learned some stuff along the way that might be useful to someone out there.

This requires Win32::OLE running on the Windows machine hosting your Outlook client.

Here’s a simple script to get the number of messages in a folder and then grab the subject text from each. Microsoft VBA methods can be found here.

`

#!perl
#
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Outlook';
	
my $outlook = Win32::OLE->new('Outlook.Application');
my $namespace = $outlook->GetNamespace('MAPI');
	
my $folder = $namespace->GetDefaultFolder(olFolderJunk);
	
my $items = $folder->Items;
	
my $count = $items->Count;
	
print "Total Messages in folder: ", $count, "n";
print "Ennumerating Messages:n";
	
for ($i = 1; $i Item($i);
	my $subject = $message->Subject;
	print “message no.”, $i, ” re: “, $subject, “n”;
	
}
	
__END__;

`

Copyright 2004-2019 Phil Lembo