[python-win32] mapi - writing to PR_BODY

Christian K. ckkart at hoc.net
Sun Feb 15 22:06:18 CET 2009


Christian K. wrote:
> def TextToStream(mapi_object, text):
>     prop_id = PR_BODY_A
>     stream = mapi_object.OpenProperty(prop_id,
>                                       pythoncom.IID_IStream,
>                                       0, mapi.MAPI_MODIFY)
>     print stream.Stat(0)
>     print stream.Write('papperlapapp\n'*10)
>     mapi.RTFSync(mapi_object,
>                  mapi.RTF_SYNC_BODY_CHANGED|mapi.RTF_SYNC_RTF_CHANGED)
>     stream.Commit(1)
>     del stream   # instead of calling Release, which I could not find

Found the solution. Partly a stupid mistake. I forgot to call
SaveChanges, for my excuse: it is not mentioned in the article above.
And the setting the PR_RTF_IN_SYNC to false is crucial to make outlook
convert the plain text to RTF.

mapi_object.SetProps([(PR_RTF_IN_SYNC, 0)])
mapi_object.SaveChanges()

Thanks Mark for your help,

Christian



More information about the python-win32 mailing list