Поделиться через


O365 & EWS: EmailMessage.SetExtendedProperty() Introduces Undesirable Behavior for Cloud

In Office 365, there is a known issue where Item.SetExtendedProperty() will prevent ResponseMessage.SendAndSaveCopy() from working correctly. Instead of sending the messaging and placing the item in the 'Sent Items' folder, the message will be sent and remain in the 'Drafts' folder.

This issue can be corrected by changing the source code of the EWS application in either of the following two ways:

1. Specify the 'Sent Items' folder via passing 'SENTFOLDEREWSID' in the method (NoteWellKnownFolderName.SentItems will not work for this case):  

var messageToSend = responseMessage.Save();

// This is our method that is introducing our repro scenario in O365.
messageToSend.SetExtendedProperty(newExtendedPropertyDefinition(newGuid("{00000000-0000-0000-0000-000000000000}"), "<String>", MapiPropertyType.String), 1);

// Send and save a copy of the replied email mesage in the default Sent Items folder.
messageToSend.SendAndSaveCopy(SENTFOLDEREWSID);

 

2. Use Item.Update() before the SendAndSaveCopy() method:

 var messageToSend = responseMessage.Save();

// This is our method that is introducing our repro scenario for the cloud.
messageToSend.SetExtendedProperty(newExtendedPropertyDefinition(newGuid("{00000000-0000-0000-0000-000000000000}"), "<String>", MapiPropertyType.String), 1);

// We update the item before sending it.
messageToSend.Update(ConflictResolutionMode.AlwaysOverwrite);

// Send and save a copy of the replied email mesage in the default Sent Items folder.
messageToSend.SendAndSaveCopy();

 

With this, you should be able to work-around this EWS issue until a fix is found. Happy coding!

 

Attached, you will find the repro code with the fix (Program.cs).

Program.cs