Getting failed in Azure Email Send API Notification - graph sendMail API

Anonymous
2023-11-22T07:30:07.7033333+00:00

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 ?

Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Akash Jadav 85 Reputation points Microsoft External Staff
    2023-12-02T09:18:48.85+00:00

    The body of the message. It can be in HTML or text format.

    Outlook mail API supports can send messages with MIME content having both HTML and text content. Refer: https://learn.microsoft.com/en-us/graph/outlook-send-mime-message

    For sending email in MIME, refer https://learn.microsoft.com/en-us/graph/api/user-sendmail?view=graph-rest-1.0&tabs=http.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    0 comments No comments

Your answer

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