1

Here is my goal :

Send an email through my interface with a custom value (Imagine, orderNumber186) then use it to filter all mails send or received by this value. for example, I have a mail address with an icon, dans when I click on it I can see all discution with him, concerning the command (or whatever) that I'm on.

Exemple of a popup with mail info

If I'm on the order number 186, il click to the icon next to the mail and I see this popup with all mail received and send concerning this order precisely (Even the name or number is not mentionned, so not just a search query). I consulted many documents from Microsoft as well as the forum, and this is all tests I carried out, with their advantages and problems :

  • internetMessageHeaders (example 2 form Microsoft doc, send mail)

With this solution, I can send a mail with my custom var easily, but it's impossible to get filtered mail with it, as it's said in this post. Despite of it, I managed to filter myself, with foreach like this :

  var listMail = [];
  try {
    //Look in all mails if they has an internetMessageHeaders with a name corresponding to var filterName
    Providers.globalProvider.graph.client
      .api("/me/mailFolders/SentItems/messages?$select=internetMessageHeaders")
      .get((err, res) => {
        if(err == null){
          //Look if they are parameters
          res.value.forEach(parameters => {
            if(parameters.internetMessageHeaders != undefined){
              //console.log(parameters);
              
              //If Yes, loop for each internetMessageHeaders values to see if they have a corresponding name, then stock it inside a listMail array
              parameters.internetMessageHeaders.forEach(element => {
                if(element.name == filterName){
                  Providers.globalProvider.graph.client
                  .api("/me/messages/"+parameters.id)
                  .get((err, res) => {
                    listMail.push(res);
                  });
                }
              });
            }
          });
        }
        else {
          console.log(err);
        }
      });
    console.log('Email List => ', listMail)
  }
  catch (error) {
    throw error;
  }

So with this method, I can get all mail that contain internetMessageHeaders values.

Now, the problem :

For optimization, we definitely can't filter all mails to get mails that contain custom var, then fetch again to get the mail and store it in an handmade array, the best way is to do it with one query, to directly have all mails concerned.

For this, I've search about a second solution : singleValueLegacyExtendedProperty

I've found how to send mail with it, and even how to recover it. When I use it, it work great when I fetch this request :

GET https://graph.microsoft.com/v1.0/me/mailFolders/SentItems/messages?$filter=singleValueExtendedProperties/any(ep:ep/id eq 'String {66f5a359-4659-4830-9070-00047ec6ac6e} Name MyName' and contains(ep/value, 'MyVar'))

My problem with this method, is that I can see all mail send, but if the client respond directly to the mail (By outlook for exemple), my var just disappear. I think that it's not the case with x-var (internetMessageHeaders), but I'm stuck on it too.

So, my question is simple :

How to set a custom value to a mail, then filter all of it just by is custom value ?

Ideally, internetMessageHeaders is perfect, I just need to filter on it with a microsoft graph query directly.

Thank you for any help

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
MelCSI
  • 11
  • 1

0 Answers0