Reading Mail messages- multithreading?

WardH 61 Reputation points


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


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

1 answer

Sort by: Most helpful
  1. Glen Scales 4,421 Reputation points

    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 . 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

    If you need to export the whole message eg something like 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 however the concurrency limit affects batching as batches can be executed asynchronous or synchronous 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 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