Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

How can I disable popup error when creating a MAPI.Sessio?

by boat73 (Scribe)
on Mar 23, 2010 at 15:12 UTC ( #830309=perlquestion: print w/replies, xml ) Need Help??
boat73 has asked for the wisdom of the Perl Monks concerning the following question:

Greating wise ones. I have a script that creates a MAPI session to a microsoft exchange server to scrape through emails. The code works great unless the Exchange server is not available. When this happens I get a popup which reads "Your microsoft exchange server is unavailable" and the script hangs until I click OK on the popup. I was hoping that someone else had run into this before and could tell me how to disable the popup so I can just capture the error and send myself an alert. The connection code is listed below. Any help as always is greatly appreciated.
my ($server, $alias, $rconn) = @_; # connect to mailbox of CN $ +alias using server $server my $mapikey = "$server\n$alias"; my $err; my $session = Win32::OLE->new(qw(Win32::OLE->new(qw(MAPI.Session)) +)) or die Win32::OLE->LastError(); # Try to logon with dynamic profile under current account. # This may need a reasonable current CDO on your machine. my $mapi = $session->Logon(undef,undef,undef,1,undef,undef,$mapike +y); return $err if $err = Win32::OLE->LastError();

Replies are listed 'Best First'.
Re: How can I disable popup error when creating a MAPI.Sessio?
by tokpela (Chaplain) on Mar 23, 2010 at 16:13 UTC

    Unfortunately, Microsoft has added these "security" features that cannot be overridden using the stock MS libraries.

    However, all is not lost!

    Check out Outlook Redemption which is a replacement for CDO and designed specifically to circumvent these issues.

    I have successfully used Outlook Redemption on several projects and it has worked well.

Re: How can I disable popup error when creating a MAPI.Sessio?
by sierpinski (Chaplain) on Mar 23, 2010 at 16:17 UTC
    Having never used Win32 (or Perl on Windows in general), this is an absolute guess, but does the Win32::OLE->LastError() cause the popup? I looked at the module docs on CPAN and it didn't mention a popup error.

    This issue does sound remotely similar to an ssh issue I was having a while back, where the new() method would return successfully, but the object would immediately be destroyed by the connection not being able to completed successfully. (the new method doesn't check for successful connection, only that the object was created, unless I'm mistaken). I resolved that issue by adding another check after the ->new() method, checking to see if the object existed, but before I tried to perform any methods on it. Can you add something like this:
    my $session = Win32::OLE->new(qw(Win32::OLE->new(qw(MAPI.Session)))) o +r die Win32::OLE->LastError(); if(!object exists) { do_something; exit; } my $mapi = $session->Logon....
    Again, that's a guess, but I hope it helps.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://830309]
Approved by ww
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2017-05-26 16:28 GMT
Find Nodes?
    Voting Booth?