【问题标题】:Save EWS mail message error保存 EWS 邮件消息错误
【发布时间】:2017-06-27 16:18:57
【问题描述】:

我无法在 Office 365 Outlook 中保存 EWS 电子邮件。

你好。我尝试使用 C# 中的 Microsoft.Exchange.WebServices 库添加电子邮件。 我创建了一个新的“Microsoft.Exchange.WebServices.Data.EmailMessage”,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope>
  <soap:Header>
    <t:RequestServerVersion Version="Exchange2007_SP1" />
    <t:TimeZoneContext>
      <t:TimeZoneDefinition Id="UTC" />
    </t:TimeZoneContext>
    <t:ExchangeImpersonation>
      <t:ConnectingSID>
        <t:PrimarySmtpAddress>email@tenant.onmicrosoft.com</t:PrimarySmtpAddress>
      </t:ConnectingSID>
    </t:ExchangeImpersonation>
  </soap:Header>
  <soap:Body>
    <m:CreateItem MessageDisposition="SaveOnly">
    <m:SavedItemFolderId>
      <t:FolderId Id="AQMkAGFjMjFlOTJlLWI3YjYtNDZlMS04MTRkLTYyYWECMTg2MmIzAC4AAAMRJLfC0jQnTqZjTdO9e1KoAQCygVW3rMc4SbvynFv3xnH6AAACAQwAAAA=" />
    </m:SavedItemFolderId>
    <m:Items>
      <t:Message>
        <t:Subject>SubjectSample</t:Subject>
      <t:Body BodyType="HTML">BodySample</t:Body>
      <t:ExtendedProperty>
        <t:ExtendedFieldURI PropertyTag="57" PropertyType="SystemTime" />
        <t:Value>2017-02-17T16:37:38.000</t:Value>
      </t:ExtendedProperty>
      <t:ExtendedProperty>
        <t:ExtendedFieldURI PropertyTag="3590" PropertyType="SystemTime" />
        <t:Value>2017-02-17T16:37:38.000</t:Value>
      </t:ExtendedProperty>
      <t:ExtendedProperty>
        <t:ExtendedFieldURI PropertyTag="3591" PropertyType="Integer" />
        <t:Value>1</t:Value>
      </t:ExtendedProperty>
      <t:From>
        <t:Mailbox>
        <t:Name>support</t:Name>
        <t:EmailAddress>support@email.com</t:EmailAddress>
        </t:Mailbox>
      </t:From>
      <t:IsRead>true</t:IsRead>
      </t:Message>
    </m:Items>
    </m:CreateItem>
  </soap:Body>
</soap:Envelope>

当我尝试保存此 EWS 消息时,我收到错误“Microsoft.Exchange.WebServices.Data.ServiceResponseException” 带有响应代码:“ErrorInvalidExchangeImpersonationHeaderData”和消息:“ExchangeImpersonation SOAP 标头必须包含用户主体名称、用户 SID 或主 SMTP 地址”。我使用 ServiceAccount 身份验证。

几天前它运行良好。

【问题讨论】:

  • 该错误告诉您 PrimarySmtpAddress 中使用的电子邮件地址不是该帐户的主电子邮件地址。如果它在几天前工作并且已经停止工作,很可能是 PrimarySMTPAddress 已更改。
  • PrimarySmtpAddress 没有改变。

标签: c# outlook office365 exchangewebservices


【解决方案1】:

我没有处理过电子邮件,但根据 msdn 链接 read Anchor Mailbox 和预约获取经验,尝试传递 Anchor Mailbox 标头。

示例代码如下

ImpersonatedUserId impersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, strAttendeeEmail);
                                    _service.ImpersonatedUserId = impersonatedUserId;
                                    if (!_service.HttpHeaders.ContainsKey("X-AnchorMailbox"))
                                        _service.HttpHeaders.Add("X-AnchorMailbox", strAttendeeEmail);
                                    else
                                        _service.HttpHeaders["X-AnchorMailbox"] = strAttendeeEmail;

【讨论】:

    猜你喜欢
    • 2023-03-21
    • 2012-09-19
    • 1970-01-01
    • 2013-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-11
    • 1970-01-01
    相关资源
    最近更新 更多