Hi,
This should be simple but I'm stuck. Trying to use PowerShell with MS Graph to send mail with a link in the body.
$body =
@"Hello World <a href = "https://microsoft.com">Microsoft</a>
@"
$headers = @{
"Authorization" = "Bearer $AccessTokenProd"
"Content-type" = "application/json"
}
$MailSender = "sender@example.com"
$URLsend = "https://graph.microsoft.com/v1.0/users/$MailSender/sendMail"
$Body =
@"
{
"message" : {
"subject": "Subject",
"body" : {
"contentType": "HTML",
"content": "$Body"
},
"toRecipients": [
"@
foreach ($ToAddress in $to) {
$Body +=
@"
{"emailAddress" : { "address" : "$ToAddress" }},
"@
}
$Body = $body.Remove($body.Length - 1, 1)
$Body += "]}}"
$Response = Invoke-RestMethod -Uri $URLsend -Headers $headers -Body $Body -Method Post
However, I get "Invoke-RestMethod : The remote server returned an error: (400) Bad Request" whenever quotes " are included in the body of the message.
How do you add an link <a href ="site">SIte Name</a> into the text body ?
I've also tried saving the body text as a file, then using get-content but this fails too.