Warm tip: This article is reproduced from serverfault.com, please click

api-mail.send不接受HTML / CSS代码

(api - mail.send is not accepting HTML/ CSS code)

发布于 2020-12-02 17:03:37

我已经从收到的电子邮件中复制了(HTML)源代码,只是为了获得该电子邮件的模板/格式,这是我在运行API时收到的错误消息:

Internal : Unexpected error Error during Web API HTTP Request
HTTP Status Code: 400
HTTP Response Content: {
  "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": "2020-12-02T17:01:05",
      "request-id": "3ab50fc1-0c13-4536-96db-bf6b9b7a736d",
      "client-request-id": "3ab50fc1-0c13-4536-96db-bf6b9b7a736d"
    }
  }
}

我已经测试了使用HTML的基本命令,例如使文本变为粗体和换行符都可以,但是任何更复杂的操作都会导致错误。

更新**感谢你的回复,我正在使用的电话如下所示:

{
  "message": {
    "subject": "[Subject]",
    "body": {
      "contentType": "HTML",
      "content": "[Email Body Content]"
    },
    "toRecipients": [
      {
        "emailAddress": {
          "address": "[Email Address]"
        }
      }
    ],
    "internetMessageHeaders":[
      {
        "name":"x-custom-header-group-name",
        "value":"Nevada"
      },
      {
        "name":"x-custom-header-group-id",
        "value":"NV001"
      }
    ]
  }
}

**另一次更新**在将内容类型更改为text / html时,出现以下错误:

Internal : Unexpected error Error during Web API HTTP Request
HTTP Status Code: 415
HTTP Response Content: {"error":{"code":"RequestBodyRead","message":"A supported MIME type could not be found that matches the content type of the response. None of the supported type(s) 'Microsoft.OData.ODataMediaType, Microsoft.OData.ODataMediaTyp...' matches the content type 'text/plain; charset=utf-8'."}}

注意,我也尝试将text / plain作为内容类型。

谢谢

Questioner
DomF
Viewed
11
Dev 2020-12-05 03:56:38

好的,我尝试了上述有效负载(只是更新了电子邮件地址),并使用Microsoft Graph Explorer进行了测试。这个对我有用 :)

这是有效载荷:

{"message":{"subject":"[Subject]","body":{"contentType":"HTML","content":"[Email Body Content]"},"toRecipients":[{"emailAddress":{"address":"test@domain.onmicrosoft.com"}}],"internetMessageHeaders":[{"name":"x-custom-header-group-name","value":"Nevada"},{"name":"x-custom-header-group-id","value":"NV001"}]}}

这是快照: 在此处输入图片说明