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

Hi Monks! I'm using the following script to receive messages from my Exchange Server.
use strict; use Win32::OLE; use Win32::TieRegistry( Delimiter=>"/" ); # my $Profile= $Registry->{"HKEY_CURRENT_USER/Software/Microsoft/Windows + NT/CurrentVersion/Windows Messaging Subsystem/Profiles//DefaultProfi +le"}; my $LogonName = $Profile; my $LogonPasswd = ""; # my $ActiveSession = Win32::OLE->new("MSMAPI.MAPISession") or die "Erro na Criacao de MAPI Session: $!"; my $ActiveMessage = Win32::OLE->new("MSMAPI.MAPIMessages") or die "Erro na Criacao de MAPI Message: $!"; # $ActiveSession->{UserName} = $LogonName; $ActiveSession->{Password} = $LogonPasswd; $ActiveSession->{NewSession} = 'False'; $ActiveSession->{LogonUI} = 'True'; $ActiveSession->{DownloadMail} = 'False'; # $ActiveSession->Signon; # $ActiveMessage->{SessionID} = $ActiveSession->{SessionID}; # $ActiveMessage->{FetchUnreadOnly} = 'False'; $ActiveMessage->{FetchSorted} = 'False'; $ActiveMessage->Fetch; my $Controle = $ActiveMessage->{MsgCount} - 1; my $i; # for $i(0..$Controle) { $ActiveMessage->{MsgIndex} = $i; print "Addr Origem.: $ActiveMessage->{MsgOrigAddress}\n"; print "Name Origem.: $ActiveMessage->{MsgOrigDisplayName}\n"; print "Data Rec....: $ActiveMessage->{MsgDateReceived}\n"; print "Assunto.....: $ActiveMessage->{MsgSubject}\n"; print "Mensagem....: $ActiveMessage->{MsgNoteText}\n"; print "*------------------------------------------------*\n"; } # $ActiveSession->Signoff; # undef $ActiveMessage; undef $ActiveSession;
However, I need to set a notify event to receive notifications messages when a new message arrive in my InBox. How can I do it? Thanks in Advance, Eustaquio.

Replies are listed 'Best First'.
Re: Using MAPI with Exchange
by JayBonci (Curate) on Apr 16, 2002 at 08:21 UTC
    Okay, so the only way that I can see on how to do this is by using the IMAPISupport::Notify COM object. Do not mistake the "::" convention for a perl module, there aren't really any perl mods for Exchange server (god help those programmers if there were). You may want to look into that documentation link at MSDN. The browse to it link is broken, but search around for the IMAPI stuff. You should be able to use the standard perl OLE/COM interfaces to use those objects.

    Sadly, I wish I knew more about that setup to be able to help you, but this seems like it might be what you're looking for. Good luck. Again, the general documentation is under MAPI. (Messaging services in MSDN). Good luck

        --jb
Re: Using MAPI with Exchange
by Corion (Patriarch) on Apr 16, 2002 at 09:44 UTC

    In addition to the other post, maybe some help comes from Inline::CPP, which (somewhat) transparently allows you to import and access C++ objects from within Perl. On my todo-list, I have a project to venture into instantiation and handling of COM objects (starting from IUnknown), and as long as perls memory management is reference-count based instead of garbage collcetion based, COM objects could almost transparently fit into Perl. But there are many MAPI pitfalls, as MAPI uses its own memory allocator (MAPIFree() must be called to deallocate structures returned by MAPI), so implementing access to real MAPI (instead of Simple MAPI) won't be easy from Perl - but Perl would be the first language to make real MAPI a nice thing to access.

    After you have managed this part, there comes another tricky part - COM callbacks into Perl. perl itself currently isn't reentrant and Perl native threads are labeled experimental for a reason. A good idea might be to implement a wrapper that exports MAPI structures via a TCP/IP port and access that gateway from Perl then - perlfunc:select is a well-understood solution to nonblocking waits.

    A small note : Perl already allows access to OLE2 objects, which export a list of callable methods. This is not what COM is about - Inline::CPP would/could allow access to VTable-interfaces, which would make using almost all COM-interfaces possible.

    perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The $d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider ($c = $d->accept())->get_request(); $c->send_response( new #in the HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web