我正在尝试使用 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/