我正在尝试发送图形API电子邮件与html正文有一个href URL,其中有&符号。
尝试将&编码为%26,收到的电子邮件中包含%26,单击时抛出404错误。
尝试将内容类型更改为"application/x-www-form-urlencoded",但未触发电子邮件。
样本代码:
我有$toJsonAddress作为一个数组。
$htmlhead="<html>
<style>
body {
font-family: 'verdana';font-size: 16px;
}
h1 {
font-family: 'verdana';font-size: 18px;color: grey;
}
h2 {
font-family: 'verdana';font-size: 18px;color: #2596be;
}
h3 {
font-family: 'verdana';font-size: 16px;color: black;
}
</style>"
#Header for the message
$HtmlBody = "<body>
<h1>test</h1>
<p>request <a href=""https://www.somedomain/help?id=sc_cat_item&sys_id=12345"">here.</a></p>
"
$content = "</body></html>" + $HtmlHead + $HtmlBody | ConvertTo-Json
Write-Output "content is -->> $content"
$URLsend = "https://graph.microsoft.com/v1.0/users/$MailSender/sendMail"
$BodyJsonsend = @"
{
"message": {
"subject": "$mailSubject",
"body": {
"contentType": "HTML",
"content": "$content "
},
"toRecipients": [
$toJsonAddress
]
},
"saveToSentItems": "false"
}
"@
Invoke-RestMethod -Method POST -Uri $URLsend -Headers $headers -Body $BodyJsonsend -ContentType "application/x-www-form-urlencoded"
JSON转换、打印和接收如下错误:
content is -->> "</body></html><html>\r\n<style>\r\n\tbody {\r\n\t\tfont-family: 'verdana';font-size: 16px;\r\n\t}\r\n\th1 {\r\n\t\tfont-family: 'verdana';font-size: 18px;color: grey;\r\n\t}\r\n\th2 {\r\n\t\tfont-family: 'verdana';font-size: 18px;color: #2596be;\r\n\t}\r\n\th3 {\r\n\t\tfont-family: 'verdana';font-size: 16px;color: black;\r\n\t}\r\n</style><body>\r\n <h1>test</h1>\r\n<p>request <a href=\"https://www.somedomain/help?id=sc_cat_item&sys_id=12345\">here.</a></p>\r\n"
Invoke-RestMethod: C:\Temp\imf4ah0e.3rb\fbb14734-21b4-4a83-a2ea-c774b3f7045a.ps1:67
Line |
67 | Invoke-RestMethod -Method POST -Uri $URLsend -Headers $headers -Body …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| {"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.ODataMediaType, Microsoft.OData.ODataMediaType,
| Microsoft.OData.ODataMediaType, Microsoft.OData.ODataMediaType,
| Microsoft.OData.ODataMediaType, Microsoft.OData.ODataMediaType,
| Microsoft.OData.ODataMediaType, Microsoft.OData.ODataMediaType,
| Microsoft.OData.ODataMediaType, Microsoft.OData.ODataMediaType,
| Microsoft.OData.ODataMediaType, Microsoft.OData.ODataMediaType,
| Microsoft.OData.ODataMediaType, Microsoft.OData.ODataMediaType,
| Microsoft.OData.ODataMediaType, Microsoft.OData.ODataMediaType,
| Microsoft.OData.ODataMediaType, Microsoft.OData.ODataMediaType,
| Microsoft.OData.ODataMediaType, Microsoft.OData.ODataMediaType,
| Microsoft.OData.ODataMediaType, Microsoft.OData.ODataMediaType,
| Microsoft.OData.ODataMediaType, Microsoft.OData.ODataMediaType,
| Microsoft.OData.ODataMediaType, Microsoft.OData.ODataMediaType,
| Microsoft.OData.ODataMediaType, Microsoft.OData.ODataMediaType,
| Microsoft.OData.ODataMediaType, Microsoft.OData.ODataMediaType,
| Microsoft.OData.ODataMediaTyp...' matches the content type
| 'application/x-www-form-urlencoded'."
1条答案
按热度按时间pcww981p1#
尝试使用字符
&
代替&
作为与号。此外,
href
属性中的URL应该用双引号括起来