See Also: Home Links Personal Site Blogroll  FriendFeed CV

Tags:

Mail Fetch

Microsoft Exchange server and the various Exchange and Outlook clients are some serious (and underused) enterprise tools, but over the years as my corpus of email and folders has grown I'd become increasingly worried that with it all stored on the server I'd be lost without it. So it was I knocked out this script to retrieve and locally archive my Exchange store

What is it

Mailfetch is a command line script ( Source )to fetch email objects from a back-end Exchange store from a specific folder (and/or subfolder) extracting message bodies into individual TXT files or a single concatenated one.

It uses win32::OLE to make MAPI (Messaging Application Programming Interface) calls via the local Exchange client i/f on the machine on which the script is run, which will more than likely be a Windows box ;-)

Script assumes you are already logged in to your Exchange client (and windows dialogue box will pop up to login if not) and uses OLE to talk through that. You can pass a password into the $session->Logon call though. With some versions of Outlook you'll get a popup dialogue when you run this script asking you to authorise access to the i/f for a specific period of time.

This script is read-only but methods are available to delete, sort, logon, logoff, getfirst, getlast, getnext, send, update etc etc ...

So you could technically extend this script to act as a full interactive command-line mail client. BUT any modifications/deletions you carry out will be reflected in your personal Exchange server store so would be best to develop using a local PST file/folder.

!!! NOTE !!! you should let the script complete its operation and not interupt it (CTRL-C) coz on one occasion (out of hundreds) I had Outlook complain about a folder being damaged, but after closing and restarting Outlook I was able to access its contents without any loss of data

Message retrieval (as performed by this script) doesnt seem to set the message as having been read, it looks like you need to specifically clear the 'unread' flag for the message

Have a search for "OLE_Messaging_Library.html" as a reference if you want to extend the script.

There's a total absence of documentation for Perl use of OLE to do this sort of thing, no suprise really as there's probably not much call for Perl based command-line access to Outlook at Redmond, but fortunately the following Usenet post outlined the basics..

From: Aaron (aibrahim1@ureach.com)
Subject: Problems accessing calendar items using win32::OLE and CDO 1.2.1
Newsgroups: comp.lang.perl.misc
2002-02-14 08:23:18 PST


See Also: Web Projects | Notes Index