在Powershell中激活安全协议
我正在使用powershell生成不同的报告,然后通过邮件发送,但我遇到了下一个异常:在Powershell中激活安全协议,powershell,sendmail,script,Powershell,Sendmail,Script,我正在使用powershell生成不同的报告,然后通过邮件发送,但我遇到了下一个异常: Authentication failed because the remote party has closed the transport stream. + CategoryInfo : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClie nt) [Send-MailMessage], SmtpExcep
Authentication failed because the remote party has closed the transport stream.
+ CategoryInfo : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClie
nt) [Send-MailMessage], SmtpException
+ FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMe
ssage
+ PSComputerName : localhost
所以,在互联网上查看时,我发现在C中,可以使用下一个代码来解决:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
我想知道如何在Powershell中执行同样的操作
编辑:
多亏了西奥,我得到了这个密码:
$protocols = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12' ; [System.Net.ServicePointManager]::SecurityProtocol = $protocols
但是我还是得到了同样的例外,所以。。。我想知道如何解决这个问题。有些报告在不同的执行过程中随机出现这种情况,有时一切正常,有时又出现这种异常情况。好的,我得到了我的答案:
我发送电子邮件的脚本是:
Start-Job -ScriptBlock {
Send-MailMessage -To $($args[0]) -From $($args[1]) -Subject $($args[2]) -Body $($args[3]) -SmtpServer $($args[4]) -UseSsl -Port "25" -Credential $($args[6]) -Attachments $($args[5])
} -ArgumentList $To, $From, $Subject, $Body, $SMTP, $DestinationExcelFilePath, $mycreds | Wait-Job | Receive-Job
现在是:
Start-Job -ScriptBlock {
$protocols = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12' ; [System.Net.ServicePointManager]::SecurityProtocol = $protocols
Send-MailMessage -To $($args[0]) -From $($args[1]) -Subject $($args[2]) -Body $($args[3]) -SmtpServer $($args[4]) -UseSsl -Port "25" -Credential $($args[6]) -Attachments $($args[5])
} -ArgumentList $To, $From, $Subject, $Body, $SMTP, $DestinationExcelFilePath, $mycreds | Wait-Job | Receive-Job
$protocols=[System.Net.SecurityProtocolType]'Ssl3、Tls、Tls11、Tls12';[System.Net.ServicePointManager]::SecurityProtocol=$protocolsNice!但是我得到了同样的例外。。。悲哀的