in reply to Checking an Exchange Box for Unread Mail

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

Replies are listed 'Best First'.
Re^2: Checking an Exchange Box for Unread Mail
by Iamwyza (Initiate) on Aug 10, 2007 at 16:38 UTC
    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.