Attachments go crazy and loose their positions when item is touched by Exchange Web Services

My fellow colleague had this customer who was using Exchange Web Services to update body of an appointment item.

He created a new appointment from Outlook with some body text, attachments in the body to the position where he wanted, subject & location. Appointment was saved as it should and life was good. This is how the appointment looked like.

image

Then he decided to update the body using Exchange web services and see how it messed up everything

image

I tried to repro it with my code but was not able to repro it and my code was updating it just fine. So I serialized the request in XML for both codes and compared them. The culprit was the Body's format and this line of code was responsible for it

bodyValueInItem.Body.BodyType1 = BodyTypeType.Text;

Instead of BodyTypeType.Text we used BodyTypeType.HTML and it resolved the issue. Although attachments were not at the same location as they all moved to the end of the body, but they were al least placed in a way that is readable.

The problem was with auto content conversion, when you set the body format to text and do not specify the HTML body. Exchange will generate a HTML copy of it automatically. This HTML generated copy does no render properly on the screen and attachment positions get changed which is rendered horribly in Outlook.