如何将凭据传递给 Send-MailMessage 命令以发送电子邮件 [英] How to pass credentials to the Send-MailMessage command for sending emails

查看:124
本文介绍了如何将凭据传递给 Send-MailMessage 命令以发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法将凭据传递给 Send-MailMessage 命令

I'm having difficulty passing my credentials to the Send-MailMessage command

这就是我正在运行的:

Send-MailMessage -smtpServer smtp.gmail.com -from 'myself@gmail.com' `
    -to 'myself@gmail.com' -subject 'Test' -attachment C:\CDF.pdf

它在消息下方出错,这显然是因为我没有通过我的 gmail 凭据

it errors with below the message which is obviously because I have not passed my gmail credentials

Send-MailMessage : The SMTP server requires a secure connection or the client was not
authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first.

我用谷歌搜索了一下,还浏览了Send-MailMessage的手册页,发现需要传递-credential"参数.

I googled a bit and also went through the man page of Send-MailMessage and found that the "-credential" parameter needs to be passed.

我的问题是:如何?

我尝试使用 Get-Credentials 如下:

I tried with Get-Credentials as below:

$mycredentials = Get-Credential

然后在弹出的框中输入我的 gmail 用户名和密码.

Then entered my usrname and password for gmail in the box that pops up.

然后我运行以下命令:

Send-MailMessage -smtpServer smtp.gmail.com -credentail $mycredentials `
  -from 'myself@gmail.com' -to 'myself@gmail.com' -subject 'Test' -attachment C:\CDF.pdf

它仍然以完全相同的错误失败.

and still it fails with the exact same error.

所以我需要你们帮助我如何将我的凭据传递给 Send-MailMessage 命令.我了解了 PScredentials,但不确定它是什么以及如何在这种情况下使用它.

So I need help from you guys on how do I pass my Credentials to the Send-MailMessage command. I learned about PScredentials but not exactly sure what it is and how to use it in this context.

推荐答案

所以..这是 SSL 问题.我所做的一切都是完全正确的.只是我没有使用 ssl 选项.所以我在我原来的命令中添加了-Usessl true"并且它起作用了.

So..it was SSL problem. Whatever I was doing was absolutely correct. Only that I was not using the ssl option. So I added "-Usessl true" to my original command and it worked.

这篇关于如何将凭据传递给 Send-MailMessage 命令以发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆