Internal Server Error when sending test email

Hornir91 20 Reputation points
2025-02-20T21:52:59.6866667+00:00

Hello.

I recently got started with Microsoft Graph API. What I need is to send mails with application-type Permission. Currently I'm testing the API, trying to send test email with Application Permission Mail.Send.

I'm getting the access token without problems but when I'm trying to send mail with the token, I'm getting an HTTP 500 error:

"{"error":{"code":"ErrorInternalServerError","message":"An internal server error occurred. The operation failed."}}"

I dumped the body which I'm sending and it's the same as in documentation, so I don't really know what's going on with that bug.

 "headers": {\n
    "Authorization": "Bearer ey...
    "Content-Length": "196", \n
    "Content-Type": "application/json", \n
    "Host": "httpbin.org", \n
    "User-Agent": "GuzzleHttp/7", \n
  }, \n
  "json": [\n
    {\n
      "message": {\n
        "body": {\n
          "content": "This is a test email.", \n
          "contentType": "Text"\n
        }, \n
        "subject": "Test Subject", \n
        "toRecipients": [\n
          {\n
            "emailAddress": {\n
              "address": "xxx"\n
            }\n
          }\n
        ]\n
      }, \n
    }\n
  ], \n

Could you provide me with some answers or how I can debug it?

Thanks in advance.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
13,111 questions
0 comments No comments
{count} votes

Accepted answer
  1. Yakun Huang-MSFT 10,400 Reputation points Microsoft Vendor
    2025-02-21T01:24:12.5733333+00:00

    Hello @Hornir91 ,

    I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to "Accept " the answer.

    Issue: An Internal Server Error occurred when sending a test email using the Graph API

    Solution: Resolved by @Hornir91 , following the below steps.

    The request body of a POST request is in an array. Removing an array helps.

    If you have any other questions or are still running into more issues, please let me know. Thank you again for your time and patience throughout this issue.

    Please remember to "Accept Answer" if any answer/reply helped, so that others in the community facing similar issues can easily find the solution.

    Thanks, Raja Pothuraju.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Hornir91 20 Reputation points
    2025-02-20T22:28:20.7966667+00:00

    I actually figured it out. I was sending POST request with body object inside an array. Removing the array helped and now it's working.

    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.