Graph API sendMail and content transfer encoding issues
We have a particular issue with MS Graph API sendMail call to send emails and content transfer encoding problems that we face - we have tried for months to figure this out on our own, but would be grateful for some guidance/tips/direction from someone
Basically, we are calling MS Graph API sendMail from a Python client code using Python's requests library's post method to send an email in MIME format. We encode the message content using base64 encoding prior to calling sendMail API since that is what is recommended in sendMail documentation here. And in the request header, we set Content-Type to "text/plain"
What we are finding is that when the email is actually sent by the sendEmail API, it is somehow swapping every 76th or so character in the message body with a "=" sign. So, the email received by recipients contains garbled email body with "=" interspersed throughout (recipients are using Outlook installed on their workstations as part of Microsoft 365 subscription to open emails). For e.g. if my message body is "This is a super long email body. 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", then when the mail is sent via the Graph API call to sendMail, then recipients see the email body in their Outlook 365 mail client like follows "This is a super long email body. 12345678901234567890123456789012=4567890123456789012345678901234567890123456789012345678901234567=90". Notice how some characters in the email body have been replaced by "=" character
Researching online, it seems like "=" is used as a soft line break by Quoted-Printable content transfer encoding scheme. But the strange thing is that in our Graph API request, we do not specify any content transfer encoding at all. So where is this encoding to Quoted-Printable happening? Is it being done by the GraphAPI sendMail code or by the Exchange online server that Graph API connects to?
We are unable to figure out the root cause and how to fix this after trying for a couple of months. As far as we can read in MS Graph API sendMail , there is no provision to set Content-Transfer-Encoding or other MIME properties as it clearly says in documentation that "Microsoft Graph does not support editing or updating MIME properties individually". Has anyone faced a similar issue before and found the root cause and fix for it? Or does anyone know which area to focus our investigation on? Should we look at Exchange server settings or is there some undocumented issue with Graph API sendMail that we should be aware of that can cause this character replacement problem?
Thanks!