Iamwyza has asked for the wisdom of the Perl Monks concerning the following question:

I want to be able to use perl to check an MS Exchange box for unread mail. I know I will need to use the OLE interface, however I have yet to find an example of doing this in perl. It seems like this should be possible, but I don't know enough about the OLE or Exchange interface elements to really know what I am doing. An example would definitely set me on the right path.
  • Comment on Checking an Exchange Box for Unread Mail

Replies are listed 'Best First'.
Re: Checking an Exchange Box for Unread Mail
by jdporter (Paladin) on Aug 10, 2007 at 14:44 UTC

    Here's a simple solution. It works for me, but you might have environmental factors (i.e. security) which might necessitate some tweaking.

    use Win32::OLE; use Win32::OLE::Const ('Microsoft Outlook'); my $ol = new Win32::OLE 'Outlook.Application'; my $sess = $ol->GetNamespace('MAPI') or die ; for my $folder ( $sess->GetDefaultFolder( olFolderInbox ) ) { print qq(\nUnRead items in folder "), $folder->FolderPath, qq(":\n +\n); my $items = $folder->Items; local( $\, $, ) = ( "\n", "\t" ); print $_->ReceivedTime->Date, $_->Subject for grep $_->UnRead, in $items; }

    It prints the received time and the subject line of each UnRead item. It does not attempt to sort the items; it prints them in the order returned by the MAPI interface.

    NB: The UnRead method seems to have a bug. It returns false for some items which appear as unread in my Outlook inbox. I suspect that these items were read and subsequently manually changed back to "unread"; and that this method is somehow able to detect this. It may be looking at the definedness of a "read on date" attribute, rather than the user-visible/settable status.

    A word spoken in Mind will reach its own level, in the objective world, by its own weight
      I suppose I needed to be more specific. This is connecting from a Unix Box. I had hoped to be able to display to a user if they had unread mail while logged into the website which is running on apache on unix.
        On Unix you can't use OLE::Win32 - as I wrote before, go for pop3/imap if the server supports it.
Re: Checking an Exchange Box for Unread Mail
by moritz (Cardinal) on Aug 10, 2007 at 14:25 UTC
    Most exchange servers offer a pop3 and/or imap interface.

    Check if your server supports that, and if yes, use it. That should be easier, and there are more examples around.

    BTW did you use the Super Search?

    Update: Perl MAPI to access Exchange Server and the followups contain some interesting links.