MAPI Logon

Hello,
I’m trying to start up a MAPI session and get my project rolling…
However, when I run my code below (it’s supposed to just log in) I get
an error telling me that ‘MAPI.Session’ is an unknown OLE server… My
code is borrowed, but is as follows:

require ‘win32ole’
mapiSession = WIN32OLE::new(‘MAPI.Session’)
WIN32OLE.const_load(mapiSession, MapiConst)
exchangeServer = ‘ex’
mailbox = ‘galthis’
logonParam = “ProfileInfo:=”+ exchangeServer + “\r” + mailbox
mapiSession.Logon(logonParam)

This kicks me the error:
test_mapisession.rb:3:in initialize': unknown OLE server:MAPI.Session’ (WIN32OLERuntimeError)
HRESULT error code:0x800401f3
Invalid class string from test_mapisession.rb:3:in `new’
from test_mapisession.rb:3

I don’t know what I’m doing wrong, or if I need something else installed
on my machine, I don’t know… I can access MAPI outlook stuff using
WIN32OLE.new(‘Outlook.Application’), but for some reason MAPI.session
doesn’t work… Any ideas?

Any help is appreciated!

Thanks,

  • Jeff

this is actually simpler to read, sorry-

so now I’ve got a simple 2-liner like so:

require ‘win32ole’
mapiSession = WIN32OLE.new(‘Mapi.session’)

with this error:
test_mapisession.rb:3:in initialize': unknown OLE server:Mapi.session’ (WIN32OLERuntimeError)
HRESULT error code:0x800401f3
Invalid class string from test_mapisession.rb:3:in `new’
from test_mapisession.rb:3

Any suggestions?

Thanks,

  • Jeff

Jeff M. wrote:

this is actually simpler to read, sorry-

so now I’ve got a simple 2-liner like so:

require ‘win32ole’
mapiSession = WIN32OLE.new(‘Mapi.session’)

with this error:
test_mapisession.rb:3:in initialize': unknown OLE server: Mapi.session’ (WIN32OLERuntimeError)
HRESULT error code:0x800401f3
Invalid class string from test_mapisession.rb:3:in `new’
from test_mapisession.rb:3

Any suggestions?

Thanks,

  • Jeff

I think you may need to have CDO (or CDONTS) installed separately in
order to call access the MAPI namespace directly. I think MAPI.Session
resides in the CDO.dll file.

Otherwise, you can call it through Outlook (assuming you have Outlook
installed):

require ‘win32ole’
outlook = WIN32OLE.new(‘Outlook.Application’)
mapi = outlook.GetNameSpace(‘MAPI’)

Hope that helps.

David

Thanks guys, that helped!

I am now on a dev box that has Exchange System Manager installed, giving
me access to MAPI32 and CDO. My session and logon work great now, but I
can’t seem to get any further using the same type of code that I used
for Outlook MAPI previously. I want to return a list of folders, but
nothing I’ve tried seems to work.

When I do the following:
require ‘win32ole’
session = WIN32OLE.new(‘Mapi.session’)
session.logon(‘profilename’)

What can I use to gain access to mailboxes? Previously, for Outlook
MAPI, I used:

outlook = WIN32OLE.new(‘Outlook.Application’)
mapi = outlook.GetNameSpace(‘MAPI’)
mailbox = mapi.Folders.Item(“Mailbox - USERNAME”)
contacts_folder = mailbox.Folders.Item(“Contacts”)

Where ‘mailbox’ defines which mailbox to use. However, I don’t think I
can do that the same way for Exchange MAPI. Does anyone know how to do
this or have any experience with it?

Any and all help is appreciated!

Thanks!!!