保存EWS邮件错误

时间:2017-06-21 16:52:52

标签: c# outlook office365 exchangewebservices

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

您好。我尝试使用C#中的Microsoft.Exchange.WebServices lib添加电子邮件。 我创建了一个新的' 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消息时,出现错误&#39; Microsoft.Exchange.WebServices.Data.ServiceResponseException&#39; 响应代码:&#39; ErrorInvalidExchangeImpersonationHeaderData&#39;和消息:&#39; ExchangeImpersonation SOAP标头必须包含用户主体名称,用户SID或主SMTP地址&#39;。我使用ServiceAccount身份验证。

几天前它运作良好。

1 个答案:

答案 0 :(得分:0)

我没有使用电子邮件,但根据msdn链接read Anchor Mailbox并且具有预约获取经验,请尝试传递Anchor Mailbox标题。

示例代码是beow

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;