windows - 使用凭据从 powershell 命令行发送电子邮件

标签 windows email powershell

我正在尝试使用 Windows 8 和 powersell 从我的 gmail ccoiunt 仅一行发送一封电子邮件。这是我使用的代码:

Send-MailMessage -smtpServer 'smtp.gmail.com' -port 587 -from '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ff92868c9a9399bf98929e9693d19c9092" rel="noreferrer noopener nofollow">[email protected]</a>' -to '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c9a4b0baaca5af89aea4a8a0a5e7aaa6a4" rel="noreferrer noopener nofollow">[email protected]</a>' -subject 'Test' -body 'Body' –UseSsl

但我不知道如何添加凭据。如何将用户名和密码添加到这一行代码中? (无需对密码进行加密)。

谢谢

最佳答案

Send-MailMessage -smtpServer 'smtp.gmail.com' -port 587 -from '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3b5642485e575d7b5c565a525715585456" rel="noreferrer noopener nofollow">[email protected]</a>' -to '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="aec3d7ddcbc2c8eec9c3cfc7c280cdc1c3" rel="noreferrer noopener nofollow">[email protected]</a>' -subject 'Test' -body 'Body' –UseSsl -Credential (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "myUsername", (ConvertTo-SecureString -String "myPassword" -AsPlainText -Force))

关于windows - 使用凭据从 powershell 命令行发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17562559/

相关文章:

java - Selenium/Java 无法与 Windows 上的 IE 一起使用

rest - 将呈现的电子邮件发送到 SendGrid 的最快方法

ios - 如何在 mailcore2 中获取电子邮件正文

java - 不使用 JavaMail 通过 Gmail 发送电子邮件

html - Powershell-帮助将哈希表转换为HTML

.net - PowerShell 属性值分配

windows - 如何在 VS 未显示时将 Visual Studio 2017 更新到最新版本?

php - 免费、可移植、全部包含在内、合而为一、基于 php Apache 的服务器?

excel - Powershell 无法向 Excel 单元格添加值

windows - 为什么 Schannel 无法从服务器接收握手?