0

我正在尝试在 PowerShell 5.0 中发送电子邮件。我现在使用的是 gmail 地址,但无法成功发送电子邮件。我确定这是由于用户名和密码造成的,但我不确定凭据的语法。

send-mailmessage -to "user2 <anotheremail@gmail.com>" -from "user1 <someemail@gmail.com>" -subject "Test mail" -SmtpServer "Smtp.gmail.com" -credential "user:someemail@gmail.com password:somepassword"

这是我得到的错误。我删除了任何个人信息:

send-mailmessage : Unable to connect to the remote server
At line:1 char:1
+ send-mailmessage -to "xxx <xxxx@gmail.com>" -from "xxxx <xxxx ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpException
    + FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage

我什至不知道我是否正确使用了凭据参数。

4

0 回答 0