Share via

Sending MIME via Graph results in mangled e-mail

Mehmet Can Cömert 111 Reputation points
2021-08-04T14:20:53.18+00:00

Hello,

We are following https://learn.microsoft.com/en-us/graph/outlook-send-mime-message, trying to send a MIME message directly via Graph API.
However, already trying to send the example mail (with adjusted Sender and Recipient of course) causes the resulting E-Mail to be mangled; the entire multipart body is encapsulated into a text/plain block which causes everything to be rendered as a single text on receiver side. Can we somehow influence this behavior?

After encoding the mail with Base64, We are sending the mail described in the tutorial using the following endpoint parameters:

POST https://graph.microsoft.com/v1.0/me/sendMail Content-type: text/plain  

 

This fails both with the Graph Explorer/Graph Tester as well as Postman; also our Software using the Graph Java SDK yields the same result.

I originally wanted to send you the received eml file as attachment but for some reason the upload on this questions page does not agree with me. Therefore I uploaded it to pastebin.com: https://pastebin.com/QDZk5bBF

Thank you in advance,
Mehmet Can Cömert

120551-email.png

Microsoft Security | Microsoft Graph
0 comments No comments

Answer accepted by question author

Mehmet Can Cömert 111 Reputation points
2021-08-10T09:22:35.847+00:00

We made a client side fix for generating the Mime Message on the usage of the Java Mail Client (Message is a javax.mail.Message).

                message.saveChanges(); // save changes so all headers etc are organized.  
  
  

On the Java Mail Client you can call save changes method to save all Mime headers before serialization.
By this way it seems like since all Mime Message Headers (including the initial Content-Type header) is available on the Message, we can send the message with an attachment without any problem:

Content-Type: multipart/mixed;  
	boundary="_002_15020177631281628585625643a7ba325bb6b5_"  
  

With the same content now I can also send an Email by using the Graph Explorer tool under:
https://developer.microsoft.com/de-de/graph/graph-explorer

It seems like your example Email defined in the Graph documentation has so many headers such as Recipient IP, internal Thread Index etc.
https://learn.microsoft.com/en-us/graph/outlook-send-mime-message
I guess therefore using it as it is not working and causing another Undelivered Message problem because of spam filters, but it is another issue.

With the fix on our client side from above, Exchange server is not adding a Content-Type anymore so it seems to be working as expected.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

2 additional answers

Sort by: Most helpful
  1. DJGummikuh 21 Reputation points
    2021-08-10T07:22:54.293+00:00

    Were you able to tackle this issue yet? This is turning into a release blocker as we need the mime sending functionality since we're doing S/MIME handling in software, so building the message object-oriented with the Graph SDK is out of the question.

    Was this answer helpful?

    0 comments No comments

  2. DJGummikuh 21 Reputation points
    2021-08-04T18:04:50.22+00:00

    FYI, the most obvious fix for us was trying to play with the multipart we transmit when doing the API call. However, setting that field to multipart/mixed caused the API to respond with a very confusing error message you might want to look into separately (it essentially tries to list up the allowed MIME types but only writes the class name of some Microsoft Type Enumeration over and over again)

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.