Reputation: 1112
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 :
Send-MailMessage : A positional parameter cannot be found that accepts argument 'True'.
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 ?
Upvotes: 0
Views: 1501
Reputation: 1446
If you check the syntax
Get-Command Send-MailMessage -Syntax
the parameter [-BodyAsHtml]
is you add is type of switch and not expecting $true
value. You can specify -BodyAsHtml:$true
Send-MailMessage [-To] <string[]> [-Subject] <string> [[-Body] <string>] [[-SmtpServer] <string>] -From <string> [-Attachments <string[]>] [-Bcc <string[]>] [-BodyAsHtml] [-Encoding <Encoding>] [-Cc <string[]>] [-DeliveryNotificationOption <DeliveryNotificationOptions>] [-Priority <MailPriority>] [-Credential <pscredential>] [-UseSsl] [-Port <int>] [<CommonParameters>]
Upvotes: 3