Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Q: Basic MAPI

360 views
Skip to first unread message

Henrik Mårtensson

unread,
Dec 22, 2000, 6:10:11 AM12/22/00
to
Hi

I'm trying to run a basic MAPI initialisation, but I get stuck with the
dispatcher.

Below I have pasted the code I'm running. Is there something that you have
to do
to make the MAPI interface available to you? I'm not running this in a MS
Exchange
office environment.

Henrik

>>> from win32com.client import Dispatch
>>> from win32com.mapi import mapi
>>> s=Dispatch("Mapi.Session")
Traceback (innermost last):
File "<interactive input>", line 1, in ?
File "D:\Program Files\Python\win32com\client\__init__.py", line 13, in
Dispatch
dispatch, userName =
dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
File "D:\Program Files\Python\win32com\client\dynamic.py", line 67, in
_GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "D:\Program Files\Python\win32com\client\dynamic.py", line 58, in
_GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx,
pythoncom.IID_IDispatch)
com_error: (-2147221005, 'Invalid class string', None, None)
>>>


Alex Martelli

unread,
Dec 22, 2000, 7:02:04 AM12/22/00
to
"Henrik Mårtensson" <henrik.m...@frontconsulting.se> wrote in message
news:nEG06.1008$Qb7....@newsb.telia.net...

> Hi
>
> I'm trying to run a basic MAPI initialisation, but I get stuck with the
> dispatcher.
...
> >>> s=Dispatch("Mapi.Session")

There is no creatable coclass (that I ever heard of) with progId
'Mapi.Session'.


> Below I have pasted the code I'm running. Is there something that you have
> to do
> to make the MAPI interface available to you? I'm not running this in a MS
> Exchange office environment.

You have to instantiate a coclass that will let you get at a
relevant MAPI object model. The progId you will use will
depend on what MAPI-supplying product you want to use --
Exchange Server, Outlook, Eudora, Netscape, whatever. With
Outlook, for example, the Session property of the Outlook
application object (which is a creatable coclass, with a
progId of 'Outlook.Application') might serve your needs.


Alex

gbr...@cix.compulink.co.uk

unread,
Dec 28, 2000, 11:11:42 AM12/28/00
to
In article <91vfs...@news2.newsguy.com>, ale...@yahoo.com (Alex
Martelli) wrote:

> "Henrik Mårtensson" <henrik.m...@frontconsulting.se> wrote in
> > message
> news:nEG06.1008$Qb7....@newsb.telia.net...
> > Hi
> >
> > I'm trying to run a basic MAPI initialisation, but I get stuck with
> > the
> > dispatcher.
> ...
> > >>> s=Dispatch("Mapi.Session")
>
> There is no creatable coclass (that I ever heard of) with progId
> 'Mapi.Session'.

There most certainly is. It comes with Outlook, among other things, and
I think lives in cdo.dll ("MAPI" is an abbreviation for "CDO" or
something). That Dispatch works fine on my machine, so I don't know
what's going wrong. Check that Outlook's installed.


Graham

Alex Martelli

unread,
Dec 28, 2000, 12:08:30 PM12/28/00
to
<gbr...@cix.compulink.co.uk> wrote in message
news:92fonu$auu$1...@plutonium.compulink.co.uk...
[snip]

> > > >>> s=Dispatch("Mapi.Session")
> >
> > There is no creatable coclass (that I ever heard of) with progId
> > 'Mapi.Session'.
>
> There most certainly is. It comes with Outlook, among other things, and
> I think lives in cdo.dll ("MAPI" is an abbreviation for "CDO" or
> something). That Dispatch works fine on my machine, so I don't know
> what's going wrong. Check that Outlook's installed.

Aha -- maybe we have a clue here. I do have Outlook installed, but,
it's Outlook 2000. "Migrating Applications to Microsoft Outlook 2000"
by Jim Groves (found on MSDN) does list among the migration concerns:
"Collaboration Data Objects (CDO) [...] now optional". And indeed,
I have no cdo.dll on my system, nor it it anywhere in my registry.

This is what Groves has to say about CDO versus MAPI:

"""
Support for Collaboration Data Objects
Formerly known as OLE Messaging and Active Messaging, CDO is an object model
that gives
applications more direct access to the Messaging Application Programming
Interface (MAPI) used by Outlook to structure its data storage than does the
Outlook object model.
Programming with CDO is more flexible than MAPI because, unlike MAPI, CDO
does not
require C or C++ as the programming language. Instead, CDO can be accessed
through
Visual Basic and Active Server Pages (ASP), as well as Visual C++Ž and any
other
development tool that creates Component Object Model (COM) objects.
"""

which I interpret as: CDO offers dual-interface COM access, so it can be
scripted from VB or anything else (Python included), while MAPI is a C/C++
only API (making it peculiar that a CDO object could possibly be named
'MAPI' something, but, whatever).

So, if Outlook 2000 is what you have, still quoting Groves:

"""
If users in your organization have already installed Outlook 2000, it is
easy for each
of them to install the CDO support.

To install CDO support
Click Start, point to Settings, and then click Control Panel.

Double-click the Add/Remove Programs icon.

In the list, click Microsoft Office 2000 or Microsoft Outlook 2000, and then
click Add/Remove.

Click Add or Remove Features.

Click the plus sign (+) next to Microsoft Outlook for Windows to open it.

Click Collaboration Data Objects, and then click Run from My Computer.
"""


Haven't tried this, so I don't know if this will indeed bring to life
a cdo.dll implementing a cocreatable "Mapi.Session" on your computer,
but, if Outlook2000 is what you're trying to work with, it sure seems
worth trying. (There are other CDO implementations, "CDO for NTS" which
is said to use SMTP and run on NT Server only, and "CDO for Exchange
2000", but they apparently use different prog-id strings to let you
create their respective 'Session' objects).


Alex

Grant Edwards

unread,
Dec 28, 2000, 2:05:25 PM12/28/00
to
In article <91vfs...@news2.newsguy.com>, Alex Martelli wrote:

>"Henrik Mårtensson" <henrik.m...@frontconsulting.se> wrote:
>
>> I'm trying to run a basic MAPI initialisation, but I get stuck
>> with the dispatcher.
> ...
>> >>> s=Dispatch("Mapi.Session")
>
>There is no creatable coclass (that I ever heard of) with progId
>'Mapi.Session'.

That's what I use:

[...]

class MapiFetcher:

def __init__(self, settings = "MS Exchange Settings"):
self.sessionSettings = settings
self.session = None
self.debugLevel=0

def Logon(self):
self.session = win32com.client.Dispatch("MAPI.Session")
self.session.Logon(self.sessionSettings)
if self.debugLevel > 1:
sys.stderr.write("MapiFetcher: MAPI.Session Logon() with settings = '%s'\n" % (self.sessionSettings,))

def CheckInbox(self):
inbox = self.session.Inbox
collmsg = inbox.Messages
if self.debugLevel > 1:
sys.stderr.write("MapiFetcher: Found %d messages in Inbox\n" % (collmsg.Count,))
messages = []

msg = collmsg.GetFirst()

while msg:
[...]
msg = collmsg.GetNext()

[...]



>> Below I have pasted the code I'm running. Is there something
>> that you have to do to make the MAPI interface available to
>> you? I'm not running this in a MS Exchange office environment.

I don't know what that means. The machine on which my code
runs has MS-Outlook installed, and there's an Exchange Server
somewhere...

>You have to instantiate a coclass that will let you get at a
>relevant MAPI object model. The progId you will use will
>depend on what MAPI-supplying product you want to use --
>Exchange Server, Outlook, Eudora, Netscape, whatever. With
>Outlook, for example, the Session property of the Outlook
>application object (which is a creatable coclass, with a
>progId of 'Outlook.Application') might serve your needs.

--
Grant Edwards grante Yow! I like your SNOOPY
at POSTER!!
visi.com

0 new messages