发送具有扩展属性的邮件时发生内部服务器错

时间:2014-03-06 15:30:12

标签: c# email exchange-server exchangewebservices

我正在使用EWS托管API。我刚开始摆弄扩展属性。所以我写了一个简单的代码来发送一个附加了扩展属性的简单邮件。

形成邮件部分我只需复制从this MSDN页面粘贴的内容。出于测试目的,我抑制了证书验证。

这是我的完整代码:

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();

我在第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()    

如果我评论第21行,代码工作正常并发送消息。那么为什么它失败了扩展属性?

1 个答案:

答案 0 :(得分:1)

我尝试与微软联系。他们给了我一个诊断工具,它捕获了Exchange Server的内部日志,并将其上传到Microsoft服务器,然后由Microsoft团队进行分析。在Exchange Server日志中,我们意识到存在MapiExceptionNamedPropsQuotaExceeded,这是在交换提供的默认配额增加时发生的。

确切的例外情况如下:

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) 

作为最终解决方案,我通过修改Windows注册表来增加命名属性配额,以在HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MSExchangeIS\<Server Name>\<Database Type-GUID>添加名为Named Props Quota的dword并将其值设置为十进制16K。这解决了这个问题。

可以找到详细步骤here

有关命名属性的更多信息,请访问here