Powershell 为什么会出现错误?发送电子邮件时出错:SMTP服务器需要安全连接,或者客户端未通过身份验证
我们收到一个错误:Powershell 为什么会出现错误?发送电子邮件时出错:SMTP服务器需要安全连接,或者客户端未通过身份验证,powershell,Powershell,我们收到一个错误: try { $credentials = new-object Management.Automation.PSCredential “ad@foc.ru”, (“dasfkjaehj5” | ConvertTo-SecureString -AsPlainText -Force) $mailParams = @{ 'To' = "prices@mits.ru" 'From
try {
$credentials = new-object Management.Automation.PSCredential “ad@foc.ru”, (“dasfkjaehj5” | ConvertTo-SecureString -AsPlainText -Force)
$mailParams = @{
'To' = "prices@mits.ru"
'From' = "ad@foc.ru"
'Encoding' = 'UTF8'
'Subject' = "340."
'Body' = "Сообщение отправлено автоматически"
'Smtpserver' = "mail.foc.ru"
'Port' = 25
'Attachments' = "E:\FTP\EMEX\price_forceauto.csv"
'Credential' = $credentials
}
Send-MailMessage @mailParams -ErrorAction Stop
}
catch {
$errorMessage = "Error sending email: $($_.Exception.Message)"
Write-Warning $errorMessage
Add-Content -Path 'E:\FTP\EMEX\error.txt' -Value $errorMessage
}
仅供参考
SSL站点现在要求您在代码中也这样做
Error sending email: The SMTP server required a secure connection, or the client was not authenticated. Server Response: 5.7.1 Local mailbox price@avto-olimp.com not found.**
错误信息非常清楚-尝试将
端口
值更改为587
或465
并将usesssl=$true
添加到$mailParams
发送电子邮件时,我们收到新的错误错误:无法从传输连接读取数据:net\io\u连接关闭。更改后,使用ssl=$true并更改端口号587和465那么,你需要询问“mail.foc.ru”
通过TLS与SMTP进行通信的端口:)我的意思是,在上面的程序中,为了保持简单,只需将其放在脚本的最上面。
# Required for use with web SSL sites
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12