Is there a way to bypass the limit of InternetMessageHeaders?

Pedro Torres 1 Reputation point
2022-03-07T14:51:21.81+00:00

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

    {"statusCode":400,
    "code":"InvalidInternetMessageHeaderCollection",
    "requestId":null,
    "date":"",
    "body":"{
        "code":"InvalidInternetMessageHeaderCollection",
        "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.
12,525 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Glen Scales 4,441 Reputation points
    2022-03-07T22:51:47.417+00:00

    If you send the message as MIME that should let you work around it https://learn.microsoft.com/en-us/graph/outlook-send-mime-message, 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 https://techcommunity.microsoft.com/t5/exchange-team-blog/named-properties-x-headers-and-you/ba-p/601652 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
    2022-03-08T10:23:30.797+00:00

    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 https://www.base64encode.org/ 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


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.