SmtpClient.ClientCertificates 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
指定應使用哪些憑證來建立安全套接層(SSL)連線。
public:
property System::Security::Cryptography::X509Certificates::X509CertificateCollection ^ ClientCertificates { System::Security::Cryptography::X509Certificates::X509CertificateCollection ^ get(); };
public System.Security.Cryptography.X509Certificates.X509CertificateCollection ClientCertificates { get; }
member this.ClientCertificates : System.Security.Cryptography.X509Certificates.X509CertificateCollection
Public ReadOnly Property ClientCertificates As X509CertificateCollection
屬性值
一個 X509CertificateCollection持有一個或多個客戶憑證的 。 預設值是從設定檔中的郵件設定屬性推導而來。
範例
以下程式碼範例建立與 SMTP 伺服器的 SSL 連線,並利用該連線發送電子郵件。
public static void CreateTestMessage(string server)
{
string to = "jane@contoso.com";
string from = "ben@contoso.com";
MailMessage message = new MailMessage(from, to);
message.Subject = "Using the new SMTP client.";
message.Body = @"Using this new feature, you can send an email message from an application very easily.";
SmtpClient client = new SmtpClient(server);
// Credentials are necessary if the server requires the client
// to authenticate before it will send email on the client's behalf.
client.UseDefaultCredentials = true;
client.EnableSsl = true;
client.Send(message);
}
備註
用戶端憑證預設為可選;然而,伺服器設定可能需要用戶端在初始連線協商時提供有效的憑證。
Note
架構會在建立 SSL 工作階段時快取 SSL 工作階段,並盡可能嘗試重複使用新要求的快取會話。 當嘗試重用 SSL 會話時,框架會使用第一個 ClientCertificates 元素(如果有的話),或嘗試重用匿名會話(如果 ClientCertificates 是空的)。