当服务器响应为5.7.0时,如何修复“SMTP服务器需要安全连接或客户端未经过身份验证”错误?

问题描述 投票:0回答:2

我确实在Gmail中打开了我不那么安全的应用程序,我认为问题是SSL。

My powershell screenshot

My current problem after changing port and $smtp

$time = get-date 
$smtpServer = “smtp.gmail.com”
$smtp.EnableSSL = $true
$smtp.Credentials = New-Object System.Net.NetworkCredential(“user”, “password”)
$smtp = new-object Net.Mail.SmtpClient($smtpServer,587) **587 to 465**
$msg = new-object Net.Mail.MailMessage
$msg.From = (“[email protected]”)
$msg.To.Add(“[email protected]”)
$body=”Your message Body”
$msg.Subject = “Mail From Gmail ” + $time
#your file location
$files=Get-ChildItem “C:\Users\Public\Pictures\LINE”
Foreach($file in $files)
{
Write-Host “Attaching File :- ” $file
$attachment = New-Object System.Net.Mail.Attachment –ArgumentList 
C:\Users\Public\Pictures\LINE\$file
$msg.Attachments.Add($attachment)
}
$smtp.Send($msg)
$attachment.Dispose()
$msg.Dispose()
powershell gmail attachment smtpclient
2个回答
0
投票

你试过改变端口吗?在我看来,你仍在使用期待TLS / SSL或STARTTLS的587。

您是否有理由不进行身份验证和使用SSL / TLS?

我已经读过,如果不支持STARTTLS,Google不会回退到纯文本SMTP。如果您在配置服务器时明确选择了“Unsecured”选项,我相信您需要使用其他端口。 25(也许)。

编辑:看起来你在send方法上缺少参数。试试这个代码。或者尝试更改更容易看起来Send-MailMessage cmdlet https://docs.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Utility/Send-MailMessage?view=powershell-5.1

$EmailFrom = "[email protected]"
$EmailTo = "[email protected]" 
$Subject = "Notification from XYZ" 
$Body = "this is a notification from XYZ Notifications.." 
$SMTPServer = "smtp.gmail.com" 
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587) 
$SMTPClient.EnableSsl = $true 
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("username", "password"); 
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)

0
投票

我的剧本中有一个类似的问题。现在在移动设备上,但如果我没记错,我最终会为使用创建一个应用密码并关闭不太安全的应用选项。

https://support.google.com/accounts/answer/185833?hl=en

© www.soinside.com 2019 - 2024. All rights reserved.