Home Ask Login Register

Developers Planet

Your answer is one click away!

Elfayer February 2016

How can I know that two emails are the same from two different mailboxes?

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 ?


Jason Johnston February 2016

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.

Elfayer February 2016

I wanted to add some code to @JasonJohnston answer.


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

// Request headers from server
  .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) {

function getMailHeader() {
  var promise = $q(function(resolve, reject) {
    // Office.context.mailbox.getCallbackTokenAsync(callback);
    outlookService.getCallbackTokenAsync(function(asyncResult, userContext) {
      if (asyncResult.status == "succeeded") {
          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 {
  return promise;

Post Status

Asked in February 2016
Viewed 3,882 times
Voted 5
Answered 2 times


Leave an answer

Quote of the day: live life