简体   繁体   中英

How do I locate email threads using Microsoft Graph SDK?

I want send an email using Microsoft Graph SDK. Then, when the recipient replies to the email, I want to associate the reply to the sent message.

So I've sent a message using

GraphClient.Users[userId].SendMail(message, true).Request().PostAsync();

Then had the user reply to it. When I read both the sent and received messages back via

GraphClient.Users[userId].MailFolders[{folderName}].Messages...;

I discovered that the ConversationId property on both were the same. I have the following questions:

  1. Is ConversationId the mechanism by which I associate emails?
  2. When I execute GraphClient.Users[userId].SendMail(message, true).Request().PostAsync() , is there a way to get back the ConversationId of the message that was just sent?
  3. I don't want to poll, so is there a way to hook into Azure where it notifies me when an email has been received for a certain user?
  4. If #3 is a "yes", can I hook into it so that it only notifies me for a reply arrived for a specific ConversationId ?
  1. ConversationId can be used to associate all the emails that belong to a particular email thread. If you want to know if a particular email was a response to an another email within the thread then use the In-Reply-to header. You can either get the In-Reply-To header by requesting the InternetHeaders https://docs.microsoft.com/en-us/graph/api/resources/internetmessageheader?view=graph-rest-1.0 (this will return all the headers) or you can request the extended property to just get that one property eg

 https://graph.microsoft.com/v1.0/users('user@domain.com')/MailFolders('Inbox')/messages/?$select=ReceivedDateTime,Sender,Subject,IsRead,inferenceClassification,InternetMessageId,parentFolderId,hasAttachments,webLink&$Top=10&$expand=SingleValueExtendedProperties($filter=(Id%20eq%20'String%200x1042'))

  1. Sends are always asynchronous in Exchange (which is what the Graph is using) so they return Void (or accepted in graph). So if you want the conversationId you will require another request to find the SentMessage and extract it from there. One way to do this is you can set the InternetMessageId on the Message your sending or create your own extended property eg these options are discussed https://github.com/microsoftgraph/microsoft-graph-docs/issues/3766

3,4 Subscription Webhooks https://docs.microsoft.com/en-us/graph/api/resources/webhooks?view=graph-rest-1.0 are what would work well for this but the ability to create a Filter (eg on the coversationId or In-reply-To) is still in the backlog (AFAIK) https://microsoftgraph.uservoice.com/forums/920506-microsoft-graph-feature-requests/suggestions/19081306-add-select-and-filter-to-webhook-resource-subs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM