Python and MAPI

Michel Orengo michelorengo at netscape.com
Wed Jan 19 10:06:22 EST 2000


As I told you, I am still a beginner wrt MAPI. It appears that my code worked but not always! In fact, I ran myself into several problems I don't understand. The strangest one is that
some code run in Interactive window, but will not run otherwise!
Moreover, I am using the lotus cc-mail version of MAPI. You are using the one provided by Outlook.

In fact, you are lucky because your version is 1.2
I know that because I have access to the MSDN Library, and that's where you can find all the command/properties of objects of the CDO (Collaboration Data Object) the OLE wrapping of
the MAPI.

If you do not have access to the MSDN Library, you can use a COM browser: it will give you the properties/methods of the objects.
Another solution is to make Python aware of the CDO object by using makepy (see QuickStartClientCom.html)
In the file generated by makepy, you will find all the classes and attributes.

What you want to do though should be not very complex. Here is a sample code (I didn't test it!), just to provide some idea:

session = win32com.client.Dispatch("MAPI.Session")
session.Logon("MS Exchange Settings")
inbox = session.Inbox
collmsg = inbox.Messages
msg = collmsg.GetFirst()
while msg:
    print "subject: ", msg.subject
    msg = collmsg.GetNext()
session.Logoff()

Note that you can also take a look at testExchange.py under the 'test' directory.

Hope this help.

Michel

Grant Edwards wrote:

> In article <slrn889o9j.3oa.grant at grante.comtrol.com>, Grant Edwards wrote:
>
> >------------------------------------------------------------
> >import win32com.client
> >import win32com.mapi.mapitags
> >
> >session = win32com.client.Dispatch("MAPI.Session")
> >session.Logon("MS Exchange Settings")
> >outbox=session.Outbox
> >collmsg=outbox.Messages
> >msgo=collmsg.Add("subj text","message text",win32com.mapi.mapitags.PR_MESSAGE_CLASS,1)
> >msgo.Recipients.Add("grante at visi.com")
> >msgo.Sender.Address="grant.edwards at comtrol.com"
> >msgo.Send(1,0)
> >session.Logoff
> >------------------------------------------------------------
> >
> >It bombs at line msgo.Sender.Address="" line with the following
> >error:
> >
> >com_error: (-2147221233, 'OLE error 0x8004010f', (1271, 'Collaboration Data Objects', ' [Collaboration Data Objects - [MAPI_E_NOT_FOUND(8004010F)]]', None, 0, -2147221233), None)
>
> If I comment out the msgo.Sender.Address line, then I get an
> error when I make the msgo.Send(1,0) call:
>
>   File "U:\Grante\python\testSend.py", line 11, in ?
>     msgo.Send(1,0)
>   File "<COMObject <unknown>>", line 2, in Send
>   File "C:\Program Files\Python\win32com\client\dynamic.py", line 207, in _ApplyTypes_
>     result = apply(self._oleobj_.InvokeTypes, (dispid, LCID, wFlags, retType, argTypes) + args)
> com_error: (-2147467259, 'Unspecified error', (17389, 'Collaboration Data Objects', ' [Collaboration Data Objects - [E_FAIL(80004005)]]', None, 0, -2147467259), None)
>
> ???
>
> --
> Grant Edwards                   grante             Yow!  My Aunt MAUREEN was
>                                   at               a military advisor to IKE &
>                                visi.com            TINA TURNER!!




More information about the Python-list mailing list