PERL - MAPI.Session

Hi,

Hello, I got this script from Active State, but when i run it, I keep getting  "Could not create a new MAPI Session".  

thanks for help.

Here's the script:

# Sender's Name and Password
#
my $sender = "username";
my $passwd = "password";

# Create a new MAPI Session
#
use Win32::OLE;
$session = Win32::OLE->new("MAPI.Session")
    or die "Could not create a new MAPI Session: $!";

# Attempt to log on.
#
my $err = $session->Logon($sender, $passwd);
if ($err) {
    die "Logon failed: $!";
}

# Add a new message to the Outbox.
#
$msg = $session->Outbox->Messages->Add();

# Add the recipient.
#
$rcpt = $msg->Recipients->Add();
$rcpt->{Name} = "username";
$rcpt->Resolve();

# Create a subject and a body.
#
$msg->{Subject} = "Test Message";
$msg->{Text} = <<EOF;
This is a sample test message.

Cheers,

Mr. Email

EOF

# Send the message and log off.
#
$msg->Update();
$msg->Send(0, 0, 0);
$session->Logoff();
d2marceloAsked:
Who is Participating?
 
clockwatcherConnect With a Mentor Commented:
In that case, you could look into using WebDAV.  Don't know how many people are actually using it (but it would be cross-platform compatible).

Sending a message:
 
  http://support.microsoft.com/kb/296713

Sending a meeting request:

  http://support.microsoft.com/kb/308373

A task request:

  http://groups.google.com/group/microsoft.public.exchange2000.development/browse_thread/thread/64a5a05da1a5a49d/a0350e751a5fef86?lnk=st&q=&rnum=1&hl=en#a0350e751a5fef86

You can also get to public and private folder stores using it.  

But, back to your original question, I don't think the MAPI problem is a perl issue.   I would guess you'd get the same problem with this vbscript.

example.vbs
--------------
set mapi = wscript.createobject("MAPI.Session")

I would see if the script above bombs and if it does post it in the VB category.  Better chance that someone there would have run into the problem you're having there than in the perl category.  Perhaps, it's a permissions issue with 2003 or something.
0
 
TintinCommented:
Was that the *complete* error message?

What version of Windows?

What user are you running the script as?

What email setup do you have?
0
 
clockwatcherCommented:
Change this:

$session = Win32::OLE->new("MAPI.Session")
    or die "Could not create a new MAPI Session: $!";

to

$session = Win32::OLE->new("MAPI.Session")
    or die "Could not create a new MAPI Session: $! -- ".Win32::OLE->GetLastError();

And check if you're getting an OLE exception.

Do you have Outlook installed?  You need window messaging installed to use MAPI.  It's installed with Microsoft's messaging clients-- Outlook, or the old Microsoft Mail, or Exchange Server Admin.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
d2marceloAuthor Commented:
Hi,  

This is the complete error message with the OLE exception

Could not create a new MAPI Session: Bad file descriptor -- Win32::OLE(0.1702) e
rror 0x800401f3: "Invalid class string" at C:\mapi.pl line 15.

I'm using windows 2003
I'm using an outook 2003 account as the script user and pwd.

Thanks,


0
 
clockwatcherCommented:
It doesn't sound like you have Outlook installed on the computer you're trying to run this on.  You need the windows messaging components installed for the MAPI controls to be installed.
0
 
d2marceloAuthor Commented:
Yes, I have outlook 2003 installed. I check the registry under Windows Messaging subsystem and the key for OLEMessaging is set to 1 as well as MAPIX, MAPI and MAPIXVER.
0
 
clockwatcherCommented:
Is there a MAPI profile set up on this machine for the user that this is running as?
0
 
d2marceloAuthor Commented:
Yes , there is.
0
 
clockwatcherCommented:
So logged into this computer as this user Microsoft Outlook works without a problem?  And your script bombs with that error under the same conditions-- logged in as this user, running as this user?  Extremely weird that you're getting the error that you're getting if that's the case.  

Sorry I'm at a loss.  As a sanity check, I'd verify that I had a CLSID registered for a MAPI.Session (although if Outlook is working, it would seem that it would have to be there).  In other words, that the following key exists:

  HKEY_LOCAL_MACHINE\SOFTWARE\Classes\MAPI.Session\CLSID

And that the CLSID referenced (most likely {3FA7DEB3-6438-101B-ACC1-00AA00423326})

  HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{3FA7DEB3-6438-101B-ACC1-00AA00423326}\InprocServer32

references an existing DLL (probably C:\Program Files\Common Files\SYSTEM\MSMAPI\1033\CDO.DLL) and that the user you're running this as has permissions to that DLL.

All of the above should be the case if Outlook runs correctly as this user... don't know where else to go.  Maybe someone else will have come across this.
0
 
clockwatcherCommented:
BTW, I would check the above registry keys as the user that you're running your script as... to verify the user has rights to the registry keys involved.
0
 
d2marceloAuthor Commented:
Thanks for the help clockwatcher, i've tried all the above but still keep getting the error message.
0
 
d2marceloAuthor Commented:
Would you know an alternative way of sending mapi mail from perl?
0
 
clockwatcherCommented:
What's the end goal?  I guess my question really is why are you using MAPI?  Are you trying to send a specific type of message (task request, calendar appointment)?  Or do you need the message to end up in Sent Items?  Are you trying to read items in a particular exchange folder?  Why did you decide to go with MAPI?  If your just interested in getting out a normal email (which is basically what you're getting with your sample code) then straight SMTP would make the most sense.

The other options (besides SMTP and MAPI) with Exchange would be IMAP, POP3 and WebDAV.  MAPI is going to be the most well-documented and the most flexible but without knowing what you're trying to do with it-- don't know if you need it.
0
 
d2marceloAuthor Commented:
yes, The reason why I need MAPI is because I'll be dealing with (task request, calendar appointment , public folders etc).
0
 
d2marceloAuthor Commented:
thanks a lot.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.