【问题标题】:How can I know that two emails are the same from two different mailboxes?我怎么知道来自两个不同邮箱的两封电子邮件是相同的?
【发布时间】:2016-02-08 10:35:23
【问题描述】:

如果我将同一封电子邮件发送到两个不同的邮箱,我希望能够判断它们是否是同一封电子邮件。

问题是itemId 对于两封电子邮件是不同的。而且我想不出办法从两封相同的电子邮件中获得唯一标识符。

从 JS 中的 Office 对象,我只能通过 Office.context.mailbox.item.itemId 获得 itemId(不同):Documentation

所以我一直试图通过以下方式从 EWS 托管 API 中找到其他东西:

EmailMessage.Bind(service, mail.ItemId, new PropertySet(ItemSchema.Id));

但我在ItemSchema 中找不到任何有用的属性。 (ItemSchema documentation)

当两封邮件在两个不同的邮箱中时,我怎么知道它们是相同的?

有没有办法比较两个id?

【问题讨论】:

  • @MrPiao 如果您阅读我提供的代码,我使用的是来自 office365-apps 上下文的 Office 对象。
  • 你是对的,我的错。

标签: c# exchange-server exchangewebservices ews-managed-api office365-apps


【解决方案1】:

对此没有 100% 的答案。它们实际上是两个独立的副本,因此它们之间没有实际的联系。您可能能够检索 RFC 822 消息 ID(尝试 InternetMessageHeaders 属性)并进行比较,但您会假设在检索之前没有修改该值。

【讨论】:

  • 什么可以改变Message-ID
  • 传输代理、传递链中的任何服务器(尽管它们可能不应该)、访问消息的其他应用程序等。
【解决方案2】:

我想在@JasonJohnston 答案中添加一些代码。

C#

[HttpPost]
public List<InternetMessageHeader> GetMailHeader(MailRequest request) {
    ExchangeService service = new ExchangeService();
    service.Credentials = new OAuthCredentials(request.AuthenticationToken);
    service.Url = new Uri(request.EwsUrl);

    ItemId id = new ItemId(request.ItemId);
    EmailMessage email = EmailMessage.Bind(service, id, new PropertySet(ItemSchema.InternetMessageHeaders));

    if (email.InternetMessageHeaders == null)
        return null;

    return email.InternetMessageHeaders.ToList();
}

JS(在这里使用 AngularJS,但你明白了)

// Request headers from server
getMailHeader()
  .then(function(response) {
    var headers = response.data;
    var messageId = findHeader("Message-ID"); // Here you get the Message-ID

    function findHeader(name) {
      for (var i in headers) {
        if (name == headers[i].Name) {
          return headers[i].Value;
        }
      }
      return null;
    }
  }, function(reason) {
    console.log(reason);
  });

function getMailHeader() {
  var promise = $q(function(resolve, reject) {
    // Office.context.mailbox.getCallbackTokenAsync(callback);
    outlookService.getCallbackTokenAsync(function(asyncResult, userContext) {
      if (asyncResult.status == "succeeded") {
        $http({
          method: "POST",
          url: serverUrl + "/api/exchange/getMailHeader",
          data: JSON.stringify({
            authenticationToken: asyncResult.value,
            ewsUrl: outlookService.ewsUrl, // Office.context.mailbox.ewsUrl
            itemId: outlookService.itemId // Office.context.mailbox.item.itemId
          })
        }).then(resolve, reject);
      } else {
        reject("ERROR");
      }
    });
  });
  return promise;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-07
    • 1970-01-01
    • 1970-01-01
    • 2017-02-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多