【发布时间】:2018-11-27 18:23:40
【问题描述】:
我正在编写一个简单的脚本(windows powershell)来发送自动电子邮件。一台计算机将一直运行,收集数据,然后定期发送电子邮件。发送电子邮件的一部分显然是收集凭据,并且由于它是自动化的,我们不能每次都有人在那里输入用户和密码。显而易见的解决方案是将信息存储在脚本中的 $user 和 $pass 变量中,但这对我来说似乎非常不安全,并且容易受到攻击。有没有更好的方法来做到这一点?也许使用用户地址设置一次安全的电子邮件连接,而不必再次输入?我是powershell的新手,所以我不太清楚最好的方法。目前我正在做的是:
$from = 'UserEmail@anotherEmail.com'
$to = 'someEmail@SomeMail.com'
$smtpServer = 'smtp-mail.outlook.com'
$smtpPort = '587'
$mailSubject = 'PowerShell Script Email Test'
$password = 'p@ssword'
$mailBody = 'body text'
$credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $from, $($password | ConvertTo-SecureString -AsPlainText -Force)
Send-MailMessage -To "$to" -From "$from" -Subject $mailSubject -SmtpServer $smtpServer -UseSsl -Credential $credentials -BodyAsHtml -Body $mailBody
非常感谢您阅读任何建议或文档
【问题讨论】:
-
当然不安全。不要那样做。查看
SecureString、ConvertFrom-SecureString和ConvertTo-SecureString以了解如何保护静态凭据。
标签: powershell email security automation email-verification