我正在尝试发送一封包含PowerShell函数 Send-MailMessage 的电子邮件,我面临各种奇怪的问题:
Send-MailMessage : A positional parameter cannot be found that accepts argument 'True'.
Send-MailMessage -Body $body -BodyAsHtml $true -From "senderadress@safrangroup.com" -Cc $recipient -Priority High - Encoding ([System.Text.Encoding]::UTF8) -SmtpServer "my.smtp.server" -Subject ("My subject") -Attachments "RESSOURCES/logo.png"
问题是当这一行执行时,它引发了一个错误:
Send-MailMessage : The specified string is not in the form required for an e-mail address.
但最奇怪的是邮件已发送到 -Cc 中指定的人员...我不明白为什么我不能添加 -To < / em>参数,最重要的是,即使出现错误,它也会发送消息...
有什么想法吗?
答案 0 :(得分:3)
如果检查语法
Get-Command Send-MailMessage -Syntax
您添加的参数[-BodyAsHtml]
是切换类型而不是期望$true
值。您可以指定-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>]