2015-04-03 202 views
2

我是新来的电源外壳scripting.I写了一个脚本这应该发送电子邮件至我的收件箱学习使用Gmail SMTP认证

我发现了几个解决方案,提高了我的脚本邮件脚本

$cred = Get-Credential 
Send-MailMessage -SmtpServer "smtp-relay.gmail.com" -Credential $cred -UseSsl -Port 587 -From "[email protected]" -To "[email protected]" -Subject "test" -Body "test" 

我得到一个错误信息如下

Send-MailMessage : Mailbox unavailable. The server response was: 5.7.0 Mail relay denied 
[117.193.79.33]. bd10sm271633igb.4 - gsmtp 
At line:2 char:1 
+ Send-MailMessage -SmtpServer "smtp-relay.gmail.com" -Credential $cred -UseSsl -P ... 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-M 
    ailMessage], SmtpException 
    + FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage 

如下我又变的端口号465或25,这让我timeout.Help操作了!

PS:远程登录于25或587是工作在电脑

感谢事先没有AV节目。

+1

有你的Gmail配置SMTP中继? [Doco](https://support.google.com/a/answer/2956491?hl=zh-TW) – 2015-04-09 00:58:57

+0

Argh !!你说的对,我不是企业客户。我会用smtp.gmail关闭。 com – Deepak 2015-04-09 14:17:46

+0

$ cred = Get-Credential Send-MailMessage -SmtpServer“smtp.gmail.com”-Credential $ cred -UseSsl -Port 587 -From“[email protected]”-To“[email protected]”-Subject “测试”-Body“测试”它工作后禁用双向验证,并允许在设置中不太安全的应用程序https://www.google.com/settings/security/lesssecureapps – Deepak 2015-04-09 14:24:49

回答

0

$ cred = Get-Credential Send-MailMessage -SmtpServer“smtp.gmail.com”-Credential $ cred -UseSsl -Port 587 -From“[email protected]” - To“[email protected]” - 主题为“Test” - 身体“测试”

此测试与Gmail的工作后,我跟着这个步骤中设置 1.停用双向验证 2.Allow不够安全的应用 Lesssecure Apps