Question

I am using EWS Managed API. I just started fiddling with Extended properties. So I wrote simple code to send a simple mail with extended property attached to it.

Forming the mail part I simply copy pasted from this MSDN page. For testing purpose I suppressed certificate validations.

This is my complete code:

1     ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
2     service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
3     service.TraceListener = new TraceListener();
4     service.TraceEnabled = false;
5 
6     service.Credentials = new WebCredentials("user@domain.com", "password@123");
7     service.Url = new Uri("https://exchng.domain.com/EWS/Exchange.asmx");
8 
9     Guid MyPropertySetId = new Guid("{C11FF724-AA03-4555-9952-8FA248A11C3E}");
10 
11     // Create a definition for the extended property.
12     ExtendedPropertyDefinition extendedPropertyDefinition = new ExtendedPropertyDefinition(MyPropertySetId, "Expiration Date", MapiPropertyType.String);
13 
14     // Create an e-mail message that you will add the extended property to.
15     EmailMessage message = new EmailMessage(service);
16     message.Subject = "Saved with extendedPropertyDefinition of two days";
17     message.Body = "The expiration date is contained within the extended property.";
18     message.ToRecipients.Add("user@domain.com"); 
19 
20     // Add the extended property to an e-mail message object named "message".
21     message.SetExtendedProperty(extendedPropertyDefinition, DateTime.Now.AddDays(2).ToString());
22 
23     // Save the e-mail message.
24     message.SendAndSaveCopy();

I am getting below exception (with no nested inner exceptions) on line 24:

An internal server error occurred. The operation failed.
   at Microsoft.Exchange.WebServices.Data.ServiceResponse.InternalThrowIfNecessary()
   at Microsoft.Exchange.WebServices.Data.ServiceResponse.ThrowIfNecessary()
   at Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute()
   at Microsoft.Exchange.WebServices.Data.ExchangeService.InternalCreateItems(IEnumerable`1 items, FolderId parentFolderId, Nullable`1 messageDisposition, Nullable`1 sendInvitationsMode, ServiceErrorHandling errorHandling)
   at Microsoft.Exchange.WebServices.Data.ExchangeService.CreateItem(Item item, FolderId parentFolderId, Nullable`1 messageDisposition, Nullable`1 sendInvitationsMode)
   at Microsoft.Exchange.WebServices.Data.Item.InternalCreate(FolderId parentFolderId, Nullable`1 messageDisposition, Nullable`1 sendInvitationsMode)
   at Microsoft.Exchange.WebServices.Data.EmailMessage.InternalSend(FolderId parentFolderId, MessageDisposition messageDisposition)
   at Microsoft.Exchange.WebServices.Data.EmailMessage.SendAndSaveCopy()    

If I comment line number 21, the code works fine and sends the message. So why it fails with extended properties?

Was it helpful?

Solution

I tried to connect with Microsoft. They gave me one diagnostic utility which captured the internal logs of Exchange Server and uploaded it to the Microsoft servers which were then analysed by Microsoft team. In Exchange Server logs it was realized that there was MapiExceptionNamedPropsQuotaExceeded, which occurs when there is an increase in the default quota what exchange supplies.

The precise exception was as follows:

Mapping 'An internal server error occurred. 
The operation failed.' used for exception          
'Microsoft.Exchange.Data.Storage.StoragePermanentException: 
Cannot get ID from name. ---> Microsoft.Mapi.MapiExceptionNamedPropsQuotaExceeded: 
MapiExceptionNamedPropsQuotaExceeded: Unable to get IDs from property names. 
(hr=0x80040900, ec=-2147219200) 

As a final solution I increased the named properties quota by modifying Windows registries to add dword at HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MSExchangeIS\<Server Name>\<Database Type-GUID> with name Named Props Quota and setting its value to decimal 16K. This solved the issue.

Detailed steps can be found here.

More information about named properties can be found here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top