1

If I send the same email to two different mailboxes, I'd like to be able to tell if these are the same email.

The problem is that the itemId is different for the two emails. And I can't figure a way to have a unique identifier from two identical emails.

From Office object in JS, I only get the itemId (that vary) via : Office.context.mailbox.item.itemId : Documentation

So I've been trying to find something else from EWS Managed API via:

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

But I can't find any useful property from ItemSchema. (ItemSchema documentation)

How can I know that two emails are the same when they are in two different mailboxes ?

Is there a way to compare two ids ?

Elfayer
  • 4,411
  • 9
  • 46
  • 76

2 Answers2

1

There is no 100% answer for this. They are actually two separate copies, so there is no actual link between them. You might be able to retrieve the RFC 822 message ID (try the InternetMessageHeaders property) and compare that, but you'd be assuming that nothing modified that value before you retrieved it.

Jason Johnston
  • 17,194
  • 2
  • 20
  • 34
0

I wanted to add some code to @JasonJohnston answer.

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 (using AngularJS here, but you get the idea)

// 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;
}
Elfayer
  • 4,411
  • 9
  • 46
  • 76