1

I'm developing an addin which needs to store some data on the mailitems. I'm using Redemption library and MAPI.Utils HrSetOneProp method.

Only in Outlook 2016, I get "Error in IMAPIProp::SaveChanges: MAPI_E_OBJECT_CHANGED" every time I do a second call to the method on the same mailitem.

Tried using Redemption RDO objects, and also plain OOM with the same results.

Here is an example:

SafeMailItem m = RedemptionGM9.SafeMailItem;
m.Item = mailItem; // this mailitem came as parameter in the function and it is the activeExplorer slection      
MAPIUtils utils = RedemptionGM9.MAPIUtils;

string sGUID = PS_PUBLIC_STRINGS.ToString("B");
int iID = m.GetIDsFromNames(sGUID, GMLINK);
if (iID != 0)
{
   //this is the method that is failing every second time for the same mailitem until you restart outlook.
   utils.HrSetOneProp(mailItem.MAPIOBJECT, iID, bForceGMPropTrue ? true :  !String.IsNullOrEmpty(sAccNo), true);
}

Marshal.ReleaseComObject(utils);
utils = null;
Marshal.ReleaseComObject(m);
m = null;

//mailitem com object is released outside this method
Community
  • 1
  • 1

1 Answers1

0

Firstly, MAPIUtils object is deprecated, and there is no reason to use it - safeMailItem implements the same methods (safeMailItem.GetIdsFromNames / Fields[]).

Secondly, why do yo pass true (Save) for the second parameter in MAPIUtils.HrSetOneProp? Would you not want Outlook to save the item whenever the user want to do that?

Where does MailItem come from?

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
  • 1-ok, I noticed that MAPIUtils is deprecated but since it's already beign used in the project Im working on, I didnt change.it. When I tried to change it and use safemailitem setfields and then call Save for the mailitem it didnt save the changes. I read over here that in these cases you need to trick outlook into thinking the mail has changed. ie mailitem.subject = mailitem.subject. But by doing that I have mails beign duplcated by some mail servers and also some IMAP synch weird behaviours. – Sebastian G Apr 26 '16 at 18:14
  • 2- As for the save parameter, I think you meant the 4th one , I wanted to force the mail to be saved when the property is added/edited. – Sebastian G Apr 26 '16 at 18:15
  • 3- Outlook._Explorer oExplorer = OutlookApp.ActiveExplorer(); Outlook.Selection Selection = oExplorer.Selection as Outlook.Selection; That selection is the mailItem, but this should not be the problem here, since I have the same issue even if I get the mailItem by entryId from the Outlook Session – Sebastian G Apr 26 '16 at 18:16
  • Is that an IMAP4 store? It really does not like when its messages are modified. – Dmitry Streblechenko Apr 26 '16 at 18:18
  • Im not sure, Im trying to get that info from a customer, but in the meanwhile,even if it is, I dont know why hrsetoneprop does work with every outlook version and not with Outlook 2016. – Sebastian G Apr 27 '16 at 15:06
  • The error essentially happen when the message is modified between the time is it opened and the time it is saved. Try to open the message using the RDO family of objects - create an instance of the RDOSession object, set its MAPIOBJECT property to Application.Session.MAPIOBJECT, call RDOSession.GetMessageFromID, set the property using RDOMail.Fields[], call RDIMail.Save. – Dmitry Streblechenko Apr 27 '16 at 16:44
  • @DmitryStreblechenko do you have a link or sample on how to properly modify RDOMail item without causing the MAPI_E_OBJECT_CHANGED error? I followed your suggestion and it still throws the exception. I've tried to use Fields[] as well as UserProperties to modify the properties and no go. – codenamezero Nov 04 '16 at 14:01
  • @codenamezero - you might want to star ta new thread and post your code. – Dmitry Streblechenko Nov 04 '16 at 14:02