Reading Mail messages- multithreading?

WardH 61 Reputation points
2022-03-31T19:49:49.087+00:00

Hi

If I want to read all mail messages in a mailbox and every folder. What is the best approach?

Is multithreading using tasks a good idea.

Like make a single connection then split up after that. Will it work make it faster or is this unsupported?

If there is a better way please advise

I am using c# btw

Thanks
Ward

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,273 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Glen Scales 4,436 Reputation points
    2022-04-04T00:35:51.423+00:00

    Multi-threading is okay you have to think in terms of throttling though and by reading which part of the Message do you need to read. eg if you just want to list the subject,receivedtime,size etc then you can list 1000 messages at a time (or per request) using the Messages endpoint https://learn.microsoft.com/en-us/graph/api/user-list-messages?view=graph-rest-1.0&tabs=http . There is a mailbox concurrency limit of 4 so in theory you could do this with up to 4 threads at a time before you would start receiving throttle notifications but you need to consider all the https://learn.microsoft.com/en-us/graph/throttling

    If you need to export the whole message eg something like https://learn.microsoft.com/en-us/graph/outlook-get-mime-message that proves more challenging as each get request is as a single request, you can batch these in the Graph but the max size of the batches is 20 messages https://learn.microsoft.com/en-us/graph/json-batching however the concurrency limit affects batching as batches can be executed asynchronous or synchronous https://gsexdev.blogspot.com/2020/09/the-mailboxconcurrency-limit-and-using.html so if you using async batches then you need to limit the batch size to 4 and don't use Multi-threading.

    Depending on what your doing with your app (and if you can afford to pay the API costs) Graph DataConnect https://learn.microsoft.com/en-us/graph/data-connect-concept-overview might be something you can look at using. This allows you to work with all the Messages within you tenant at (massive)scale as your no-longer restricted by working with mailbox access API's.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.