简体   繁体   English

Powershell电子邮件发送错误

[英]Powershell email sending with an error

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 : 我正在尝试使用PowerShell函数Send-MailMessage发送电子邮件,并且遇到了许多非常奇怪的问题:

  • First of all, the -To parameter is not proposed when I write this function in the PowerShell ISE. 首先,当我在PowerShell ISE中编写此函数时,不建议使用-To参数。 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'. 而且,如果无论如何我都尝试添加它,如果出现以下错误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. 因此,为了绕过此问题,我发现我可以使用-Cc参数向某人发送电子邮件。 So my call to Send-MailMessage looks like the following 所以我对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"

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... 但是最奇怪的是,邮件已经发送到-Cc中指定的人了 ...我不明白为什么我不能添加此-To参数,最重要的是为什么即使在发送邮件时也是如此有一个错误...

Any idea ? 任何想法 ?

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. 您添加的参数[-BodyAsHtml]是开关类型,并且不期望$true值。 You can specify -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>]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM