Until now we have only been reading data from MAPI. The most important ways of writing data to MAPI are:
message.SetProps(): the opposite of GetProps()
message.SaveChanges(): save changes done with GetProps()
message.CreateAttach(): create a new attachment
folder.CreateMessage(): create a new message
However, if you were to simply take the code we have created until now and added any of these functions, an exception would be raised. This is because all the flags we have been passing were 0, and most functions default to read-only access. The calls we have to change are:
OpenEntry(entryid, None, MAPI_MODIFY) : Open a message or folder with write permissions
OpenProperty(proptag, IID_IStream, 0, MAPI_MODIFY): Open an existing stream with write permissions
OpenProperty(proptag, IID_IStream, 0, MAPI_MODIFY|MAPI_CREATE): Open a new stream with write permissions, or truncate the existing stream
This allows you to write to the objects:
message.SetProps([SPropValue(PR_SUBJECT, 'new subject')])
stream.Write('hello')
Although changes on messages are not saved to disk until SaveChanges() is called on messages, changes on folders and stores are immediate and do not require a SaveChanges() call.