我可以将Send-MailMessage cmdlet与CRT证书一起使用吗?

时间:2016-10-14 14:56:46

标签: powershell ssl tls1.2

我有这段代码:

Clear-Host
$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]::SecurityProtocol = 'Tls,TLS11,TLS12'
    [System.Net.ServicePointManager]::ServerCertificateValidationCallback = { return $true }

    foreach ($recipient in $to)
    {
        Write-Host "Sent to $to"
        Send-MailMessage -SmtpServer $smtpserver -UseSsl -From $from -To $recipient -Subject $subject -BodyAsHtml $body -Encoding ([System.Text.Encoding]::UTF8)
    }
}
else
{
    Write-Host "Configuración"
}

我想知道我是否可以使用CRT认证,而不是设置ServerCertificateValidationCallback = TRUE

这是一个测试环境。

CRT证书已添加到SMTP服务器。

0 个答案:

没有答案