【发布时间】:2022-02-26 17:53:43
【问题描述】:
我正在尝试使用 PowerShell 发送电子邮件,但需要使用 TLS。有什么方法可以使用 Send-MailMessage cmdlet 做到这一点?
这是我的代码:
$file = "c:\Mail-content.txt"
if (test-path $file)
{
$from = "afgarciact@gmail.com"
$to = "<slopez@comfama.com.co>","<carloscu@comfama.com.co>"
$pc = get-content env:computername
$subject = "Test message " + $pc
$smtpserver ="172.16.201.55"
$body = Get-Content $file | Out-String
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { return $true }
foreach ($recipient in $to)
{
write-host "Sent to $to"
Send-MailMessage -smtpServer $smtpserver -from $from -to $recipient -subject $subject -bodyAsHtml $body -Encoding ([System.Text.Encoding]::UTF8)
}
}
else
{
write-host "Configuración"
}
非常感谢!
【问题讨论】:
标签: powershell