【发布时间】:2017-07-27 13:20:27
【问题描述】:
我正在尝试使用 PowerShell 函数 Send-MailMessage 发送电子邮件,但我遇到了各种非常奇怪的问题:
- 首先,我在PowerShell ISE中写这个函数的时候没有提出-To参数。如果我尝试添加它,如果出现以下错误
Send-MailMessage : A positional parameter cannot be found that accepts argument 'True'. - 为了绕过这个问题,我发现我可以使用 -Cc 参数向某人发送电子邮件。所以我对 Send-MailMessage 的调用如下所示
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 参数,最重要的是为什么即使有错误它也会发送消息......
有什么想法吗?
【问题讨论】:
-
$recipient的完整值是多少? -
我不能公布真正的价值,但它和“name.subname@group.com”一模一样
-
不确定这是否是唯一的问题,但
-BodyAsHtml $true是(afaik)错误,它应该只是-BodyAsHtml或-BodyAsHtml:$true
标签: powershell email