sendmail getting error

dashandwerk.net (Frank Lehmann) 0 Reputation points
2023-04-07T16:00:18.76+00:00

Hi, i am not able to send simple mail like this: {"message": {"subject": "Hallo Welt","body": {"contentType": "html","content": "<html><body>Noch mehr Welt<br>Mit freundlichem Gruß<br><br>dashandwerk.net<br>Frank Lehmann<br>Lindenstrasse 10a<br>28755 Bremen<br><br>Tel:0421-56507289<br>Mail: @dashandwerk.net<br><br><br><a href="https://reviewforest.org/dashandwerk">Für jede Bewertung pflanzen wir einen Baum !</a></body></html>"},"toRecipients": [{"emailAddress": {"address": "@dashandwerk.net"}}]},"saveToSentItems": "true"} getting error:
{"error":{"code":"BadRequest","message":"Unable to read JSON request payload. Please ensure Content-Type header is set and payload is of valid JSON format.","innerError":{"date":"2023-04-07T15:56:53","request-id":"d78db294-12cd-42b5-82d7-be48c17cd7e7","client-request-id":"d78db294-12cd-42b5-82d7-be48c17cd7e7"}}}

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

1 answer

Sort by: Most helpful
  1. HarmeetSingh7172 4,826 Reputation points
    2023-04-07T20:15:16.24+00:00

    Hello dashandwerk.net (Frank Lehmann), Thanks for reaching out! This error occurs because your payload is not in a valid JSON format. You have to escape the quotation marks. Use \" instead of ". Additionally, the value of "saveToSentItems" property should be a Boolean instead of string. Please re-check your JSON body and try to execute the send mail graph endpoint again. I've modified the request body you were using and now it's giving expected response.

    { 
        "message": {
            "subject": "Hallo Welt",
            "body": {
                "contentType": "html",
                "content": "<html><body>Hello<br>Mit freundlichem Gruß<br><br>dashandwerk.net<br>Frank Lehmann<br>Lindenstrasse 10a<br>28755 Bremen<br><br>Tel:0421-56507289<br>Mail: ******@dashandwerk.net<br><br><br><a href=\"https://reviewforest.org/dashandwerk\">Für jede Bewertung pflanzen wir einen Baum !</a></body></html>"
            },
            "toRecipients": [
                {
                    "emailAddress": {
                        "address": "shivam@6***bg.onmicrosoft.com"
                    }
                }
            ]
        },
        "saveToSentItems": true
    }
    
    

    Hope this helps. If the answer is helpful, please click Accept Answer and kindly upvote. If you have any further 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.