简体   繁体   English

发送电子邮件 Send-MailMessage - PowerShell

[英]Send email Send-MailMessage - PowerShell

I have to send an email using a pre-defined account, I have all the information, smtp server name, email address, user, password.我必须使用预定义的帐户发送电子邮件,我拥有所有信息、smtp 服务器名称、电子邮件地址、用户、密码。 This account uses TTL.此帐户使用 TTL。 How to create the script to send this email using VBA.如何创建脚本以使用 VBA 发送此电子邮件。 I'm having problems with the Credential parameter, I don't know how to put the username and password我的 Credential 参数有问题,我不知道如何输入用户名和密码

"Send-MailMessage -To 'xxxx@yyy' -from 'kkk@yyyy' -subject 'Teste' -body 'Testando o envio' -stmpserver 'smtp.gmail.com' -UseSSL -Port 587 -Credential ( I don't know how to make this parameter ) " “Send-MailMessage -To 'xxxx@yyy' -from 'kkk@yyyy' -subject 'Teste' -body 'Testando oenvio' -stmpserver 'smtp.gmail.com' -UseSSL -Port 587 -Credential(我不不知道如何制作这个参数)”

See this SO post how to convert a username-password-pair into a PowerShell credential:请参阅此 SO 帖子如何将用户名-密码对转换为 PowerShell 凭据:

$userName = 'test-domain\test-login'
$password = 'test-password'

$pwdSecureString = ConvertTo-SecureString -Force -AsPlainText $password
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $userName, $pwdSecureString

Send-MailMessage -Credential $credential ...

Note: Try to avoid putting passwords into your scripts.注意:尽量避免将密码放入脚本中。 Store it somewhere safely , or let the user input it with Read-Host or Get-Credential .将它安全地存储在某个地方,或者让用户使用Read-HostGet-Credential输入它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM