Mapi Attachment method WriteToFile throws exception ...

Peter Curran pcurran at intraspect.com
Mon Jun 23 19:12:23 EDT 2003


Hello - 

I'm getting an exception when I try to save an email attachment
gathered from an Exchange server using Mapi and python com utils.

The COM exception I'm getting back in indecipherable (to me) and I'm
hoping that someone in this group can help me dereference the error so
that I can move on.  My code is included below - it's ugly but it
works well other than where I try to save the attachment - maybe
someone can use it.

Is there a place where I can look up CDO exceptions?  Has anyone else
resolved this problem?

The exception:

  File "<COMObject <unknown>>", line 2, in WriteToFile
  File "C:\Python22\Lib\site-packages\win32com\client\dynamic.py",
line 237, in _ApplyTypes_
    result = apply(self._oleobj_.InvokeTypes, (dispid, LCID, wFlags,
retType, argTypes) + args)
com_error: (-2147352567, 'Exception occurred.', (17389, 'Collaboration
Data Objects', ' [Collaboration Data Objects - [E_FAIL(80004005)]]',
None, 0, -2147467259), None)


The code:

"""
file - getvwstofile.py
opens a folder in an exchange inbox, iterates over its contents, saves
attachments on messages to disk
"""
import sys

s = Dispatch("Mapi.Session")
s.Logon()
vw = s.Inbox.Folders[9] #open the folder i want

#now iterate over the messages
for x in range(1, len(vw.Messages) + 1):
    sub = vw.Messages[x].Subject

    bContinue = 0
    z = sub.find("Alert, ")
    #i only want messages with particular subjects
    if z != -1:
        item = vw.Messages[x]
        attaches = item.Attachments
        if attaches:
            for i in range(1, len(attaches) + 1):
                atitem = attaches[i]

                #here's the weirdness - got the attachment, but can't
save it!
                #i've also tried atitem.WriteToFile("c:\vsmsgs\%s" %
(atitem.Name))
                if(atitem):
                    atitem.WriteToFile("c:\\vsmsgs\\%s" %
(atitem.Name))
s.Logoff()
s = None




More information about the Python-list mailing list