Microsoft Graph - Send email with text and html bodies

3.6k views Asked by At

How can I send a message using Microsoft Graph that would have both, text AND html bodies?

1

There are 1 answers

0
eugene On

For those finding this message sometime later, pulling your hair out trying to understand why Microsoft didn't make this clear in the documentation, see this post: Can Office 365 REST API send an email with both plain text and HTML body?

I've confirmed this on my end - once the graph API request is made, the Exchange server does, in fact, strip the HTML characters, creates a multipart message (with boundaries) and delivers in the appropriate format.

In my case, I only needed to set the following:

body.contentType = BodyType.HTML;
body.content = myCustomEmailObject.getHtml();

Here's an example of what the raw response (email source) looks like in gmail:

--_000_CO6PR14MB42581EA88B5BE054EFE62113CF449CO6PR14MB4258namp_
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

This is the content
And this is a new line...

--_000_CO6PR14MB42581EA88B5BE054EFE62113CF449CO6PR14MB4258namp_
Content-Type: text/html; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<html>
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dus-ascii"=
>
</head>
<body>
<b>This is the content</b><br>
And this is a new line...
</body>
</html>

--_000_CO6PR14MB42581EA88B5BE054EFE62113CF449CO6PR14MB4258namp_--