Is there a way to bypass the limit of InternetMessageHeaders?

Pedro Torres 1 Reputation point

Using Microsoft Graph API to append a list of InternetMessageHeaders to a mail, I get the following error:

        "message":"Maximum number of headers in one message should be less than or equal to 5."

Why is there a maximum limit, especially when the normal number of default headers is greater then that? And is there a way to bypass these limit?

Thank you

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

2 answers

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

    If you send the message as MIME that should let you work around it, any reason you setting such a high number of individual headers ? if they are all small headers you could just create one header and encode the key/values as a json doc (this is a method that is used by the Antispam/hygiene processes). Creating large number of X-headers can lead X-haustion see to this is most likely the reason they put that limitation in.

    1 person found this answer helpful.
    0 comments No comments

  2. Pedro Torres 1 Reputation point

    Hi Glen, thank you for your reply.
    I wanted to set a high number of headers - around 10 - for compatibility with an existing system that expects individual headers in my company. The solution using just one header unfortunately would require a lot of rewriting of that system to accept the JSON key values in one header, so it isn't the preferred solution...
    In regards to using MIME, I tried doing the following in the Graph Explorer:

    • Using GET with the $value segment in the url request, I got a message (which already had 3 custom headers) in the MIME format;
    • I added 7 additional headers to that content and used to encode that into base 64 (using that encoder to split lines into 76 characters).
    • Sent that base64 string using Graph.

    The email that resulted from that did not include the 7 additional headers but included the original 3 custom headers (I added those previously using Office.context.maibox.item.setAsync() in compose mode). What could be the issue stopping those headers from being sent/received?

    Any help would be much appreciated