【发布时间】:2020-05-11 12:16:39
【问题描述】:
PowerShell 电子邮件功能如下:
$Attachment = "C:\Users\HP\Desktop\Tools\Email_on_failure\errorlist.txt"
$Subject = "Errors!"
$Body = "See attachment"
$SMTPServer = "smtp.mail.yahoo.com"
$SMTPPort = "465"
Send-MailMessage -From gs4u@yahoo.com -to gs4u@outlook.com -Subject $Subject -Body $Body -SmtpServer $SMTPServer -port $SMTPPort -UseSsl -Credential (Get-Credential) -Attachments $Attachment
但我在下面收到此错误:
Send-MailMessage : Smtp server returned an invalid response.
At C:\Users\HP\Desktop\Tools\Email_on_failure\EOF.ps1:28 char:2
+ Send-MailMessage -From gowthamsaarthy4u@yahoo.com -to gowthamsaar ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpException
+ FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage
那也是!处理时间约为 20 秒。请帮忙!
【问题讨论】:
-
在您的示例中,您似乎缺少
Get-Credential周围的右括号 -
@derekbaker783 你好。实际上它确实有一个右括号。我在编写查询时错过了。谢谢告知。现在用括号更新了问题。请帮帮我。
-
不带附件试试看是否可行
-
$SMTPPort应该是 int 类型。删除那里的引号。
标签: powershell powershell-cmdlet