I am trying to send an email with the PowerShell function Send-MailMessage, and I am in front of various issues that are quite strange :
- First of all, the -To parameter is not proposed when I write this function in the PowerShell ISE. And if I try to add it anyway, if have the following error
Send-MailMessage : A positional parameter cannot be found that accepts argument 'True'. - So to bypass this problem, I found that I could send an email to someone using the -Cc parameter. So my call to Send-MailMessage looks like the following
Send-MailMessage -Body $body -BodyAsHtml $true -From "[email protected]" -Cc $recipient -Priority High - Encoding ([System.Text.Encoding]::UTF8) -SmtpServer "my.smtp.server" -Subject ("My subject") -Attachments "RESSOURCES/logo.png"
The problem is that when this line is executing, it's raising an error :
Send-MailMessage : The specified string is not in the form required for an e-mail address.
But the most strange here is that the mail has been send to the personn specified in -Cc... I don't understand why I can't add this -To argument, and most of all why it is sending the message even if there is an error...
Any idea ?
$recipient?-BodyAsHtml $trueis (afaik) wrong, it should either be only-BodyAsHtmlor-BodyAsHtml:$true