# MAPI Logon

**URL:** <https://www.ruby-forum.com/t/mapi-logon/133036>\
**Category:** Ruby\
**Created:** [March 26, 2008, 10:46pm UTC](https://www.ruby-forum.com/t/mapi-logon/133036 "2008-03-26T22:46:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [March 26, 2008, 10:46pm UTC](https://www.ruby-forum.com/t/mapi-logon/133036/1 "2008-03-26T22:46:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [March 26, 2008, 11:51pm UTC](https://www.ruby-forum.com/t/mapi-logon/133036/2 "2008-03-26T23:51:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [March 27, 2008, 5:41pm UTC](https://www.ruby-forum.com/t/mapi-logon/133036/3 "2008-03-27T17:41:22Z")

</div>

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’)

> **[Ruby on Windows](http://rubyonwindows.blogspot.com/search/label/outlook)**
>
> On using the Ruby programming language on the Microsoft Windows platform

Hope that helps.

David

> **[Ruby on Windows](http://rubyonwindows.blogspot.com)**
>
> On using the Ruby programming language on the Microsoft Windows platform

---

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [March 27, 2008, 11:05pm UTC](https://www.ruby-forum.com/t/mapi-logon/133036/4 "2008-03-27T23:05:03Z")

</div>

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!!!
