Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Security 使用PowerShell V4通过gmail发送邮件_Security_Powershell_Gmail_Powershell 4.0_Powershell Ise - Fatal编程技术网

Security 使用PowerShell V4通过gmail发送邮件

Security 使用PowerShell V4通过gmail发送邮件,security,powershell,gmail,powershell-4.0,powershell-ise,Security,Powershell,Gmail,Powershell 4.0,Powershell Ise,我一直在使用此PowerShell脚本在打开时向我发送电子邮件 $EmailFrom = "notifications@somedomain.com" $EmailTo = "anything@gmail.com" $Subject = "sample subject" $Body = "sample body" $SMTPServer = "smtp.gmail.com" $SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer,

我一直在使用此PowerShell脚本在打开时向我发送电子邮件

$EmailFrom = "notifications@somedomain.com"
$EmailTo = "anything@gmail.com" 
$Subject = "sample subject" 
$Body = "sample body" 
$SMTPServer = "smtp.gmail.com" 
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587) 
$SMTPClient.EnableSsl = $true 
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("YOURUSERNAME", "YOURPASSWORD"); 
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
我将$EmailTo更改为我的电子邮件地址,将YOURUSERNAME/YOURPASSWORD更改为我正确的登录信息

事实上,我知道这在上个月起了作用。我最近更改了我的Gmail密码,显然这个脚本停止工作了。但是,我已将YOURPASSWORD更改为正确的新密码,现在由于某种原因,我在打开时出错:

$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
Exception calling "Send" with "4" argument(s): "The SMTP server requires a secure connection or the client was not 
authenticated. The server response was: 5.5.1 Authentication Required. Learn more at"
At line:9 char:1
+ $SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : SmtpException
我使用的是Windows 7 Ultimate 64位,我相信我使用的是PowerShell V2,但今天更新为V4,因为我认为这可能是问题所在

我还打开了Gmail设置中的不安全应用,因为有人说这可能是问题所在。事实并非如此,直到今天,我仍在犯错误


你知道是否仍然可以通过PowerShell发送Gmail吗?还是我错过了什么?谢谢你的帮助

我也有同样的问题,但Gmail给我发了一封邮件,上面有“不太安全的应用”的链接,我把它放在上面,然后它就工作了。这里的链接只是改变你的谷歌用户名用户名

https://accounts.google.com/AccountChooser?Email=USERNAME@gmail.com&continue=https://www.google.com/settings/security/lesssecureapps?rfn%3D27%26rfnc%3D1%26eid%3D3301110864727181130%26et%3D0%26asae%3D2

除了显而易见的(仔细检查您的用户名/密码)之外,您是否尝试过使用
Send-MailMessage
cmdlet?不太可能。您是否有当前可用的脚本D
发送邮件消息-从$EmailFrom-到$EmailTo-主题$Subject-正文$Body-使用SSL-SmtpServer$SmtpServer-端口587-凭证(获取凭证)
-在凭证提示中输入用户名和密码谢谢,但我需要的是它完全自动。就像我的脚本一样,它将自己输入凭证。你知道我的意思吗你是怎么让Gmail给你发送链接的?你应该将这些步骤添加到你的答案中,因为这将极大地帮助有类似问题的用户(此外,我怀疑你的特定链接是否适用于其他用户。我猜Gmail会为每一个请求链接的不太安全的应用程序生成一个新链接,因此在这种情况下,正确的答案应该是你应该添加的步骤)