2016-10-10 17 views
0

PowerShellを使用して電子メールを送信しようとしていますが、TLSを使用する必要があります。 Send-MailMessageコマンドレットを使用して私はそれを行うことができますか?Send-MailMessageコマンドレットでTLSを使用できますか?

これは私のコードです:

$file = "c:\Mail-content.txt" 

if (test-path $file) 
{ 

    $from = "[email protected]" 
    $to = "<[email protected]>","<[email protected]>" 
    $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" 
} 

どうもありがとう!

答えて

0

あなたが-UseSslスイッチを指定していることを確認してください:あなたが確認するには

Send-MailMessage -SmtpServer $smtpserver -Port 465 -UseSsl -From $from -To $recipient -Subject $subject -BodyAsHtml $body -Encoding ([System.Text.Encoding]::UTF8) 

-Portパラメータを使用して、SMTPサーバがTLSを超えるSMTPのための特定のポートを使用している場合

Send-MailMessage -SmtpServer $smtpserver -UseSsl -From $from -To $recipient -Subject $subject -BodyAsHtml $body -Encoding ([System.Text.Encoding]::UTF8) 

をTLSは常にネゴシエートされ(SSL 3.0ではなく)、ServicePointManagerクラスのSecurityProtocolプロパティを設定します。

[System.Net.ServicePointManager]::SecurityProtocol = 'Tls,TLS11,TLS12' 
+0

しかし、それはSSLと言います。代わりにTLSを使用していますか? –

+1

これは、サーバーが提供するものは何でも交渉します。デフォルトでは、TLS 1.0またはSSL 3.0の最高値が –

+0

です。したがって、TLS 1.2を使用するOffice 365の場合は、正しく動作しますか? –

関連する問題