BenjaminWolff-2349 avatar image
0 Votes"
BenjaminWolff-2349 asked BenjaminWolff-2349 commented

Wrong encoding when sending mails with HTML body using MS Graph API and Java SDK client


I'm sending emails using the MS Graph API and the Java Graph SDK ( ). However, I can't control the encoding used in the email body. It seems to sometimes randomly pick between "Windows-1252" or "iso-8859-1". This leads to garbled symbols in the email body.

For example, I'm setting the mail body in Java like so:

 ItemBody body = new ItemBody();
 body.contentType = BodyType.HTML;
 body.content = "<p>Test Mail über Outlook365. öäü#+ß^°123§%&/()=?`´#'*~+-<>|,;.:-_\"áàúù\\{}[]âûôêéè</p>";
 message.body = body;

The email body seems to be still encoding in UTF-8, but the wrong charset header displays many of the characters wrong in the email:


The encoding header in the HTML email body is "Windows-1252", which is wrong and should always be "utf-8".

I'm already setting the "-Dfile.encoding=UTF-8" start parameter and the return value of "Charset.defaultCharset()" is also UTF-8. Is there any way I can control the content encoding of mails send via the Graph API using the Java SDK client?

Btw, I'm having the same issues with content in events and cancellation messages that I create using the API.

Best regards,

enc-problem.png (9.1 KiB)
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

  • Just to isolate the issue out of SDK can you try repro the issue with Graph explorer or POSTMAN and see if you can repro the issue?

  • If you can still repro the issue with latest Java SDK, then consider report the issue at Github.

0 Votes 0 ·

Thanks a lot for your reply.

I tried to reproduce the issue using POSTMAN, but the behavior is different. Using the exact same HTML body in a raw JSON request body in POSTMAN, the encoding behavior of the mail is different. In this case, it ends up with an ISO-8859-1 encoding and no garbled characters in Outlook.

Using the same HTML body and the Java SDK, I can reliably reproduce the described encoding issue, leading to garbled characters in Outlook. It therefore seems to be an issue that is specific to the Java SDK. I will try to create a small project that reproduces this issue and create an issue at Github, as you suggested.

Best regards,

0 Votes 0 ·

Just in case someone stumbles over the same issue, I found the problem and described the solution in the Github issue here:

0 Votes 0 ·

0 Answers