I'm working on sending emails using the Microsoft Graph Mail API.
So far, I've managed to send emails with either TEXT or HTML content. Now, I'm looking to set up a request body that can handle emails containing both TEXT and HTML simultaneously.
Can you guide me on how to structure the request body for this scenario?
This is the request body i have used for attempting the sendMail API request :
URL : https://graph.microsoft.com/v1.0/users/{{SourceObjectId}}/sendMail
TYPE : POST
{
"saveToSentItems": true,
"message": {
"toRecipients": [
{
"emailAddress": {
"address": "<mailladdress>"
}
}
],
"subject": "MAIL SUBJECT",
"body": {
"contentType": "multipart/alternative",
"content": [
{
"text/html": "<html><body><h1>Hello</h1><p>This is a test email with <b>HTML</b> content.</p></body></html>"
},
{
"text/plain": "Hello\nThis is a test email with content"
}
]
}
}
}
And I am getting the response like this :
{
"error": {
"code": "RequestBodyRead",
"message": "An unexpected 'StartArray' node was found when reading from the JSON reader. A 'PrimitiveValue' node was expected."
}
}
Can you assist me in making any necessary adjustments to the request body ?