我试图发送图形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>rn<style>rntbody {rnttfont-family: 'verdana';font-size: 16px;rnt}rnth1 {rnttfont-family: 'verdana';font-size: 18px;color: grey;rnt}rnth2 {rnttfont-family: 'verdana';font-size: 18px;color: #2596be;rnt}rnth3 {rnttfont-family: 'verdana';font-size: 16px;color: black;rnt}rn</style><body>rn <h1>test</h1>rn<p>request <a href="https://www.somedomain/help?id=sc_cat_item&sys_id=12345">here.</a></p>rn"
Invoke-RestMethod: C:Tempimf4ah0e.3rbfbb14734-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'."
尝试使用字符&
代替&
。
另外href
属性中的URL应该用双引号括起来
$HTMLBody = "<html><body><p>Portal: <a href=""https://sampledns/overview?ff=abc&ln=xyz"">some text</a></p></body></html>"