SmtpClient.ClientCertificates 屬性

定義

指定應該用來建立 Secure Sockets Layer (SSL) 連線的憑證。Specify which certificates should be used to establish the Secure Sockets Layer (SSL) connection.

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

X509CertificateCollection,保存一個或多個用戶端憑證。An X509CertificateCollection, holding one or more client certificates. 預設值是擷取自組態檔中的郵件組態屬性 (Attribute)。The default value is derived from the mail configuration attributes in a configuration file.

範例

下列程式碼範例會建立與 SMTP 伺服器的 SSL 連線,並使用連接傳送電子郵件。The following code example establishes an SSL connection with the SMTP server and uses the connection to send an email.

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);
}

備註

依預設,用戶端憑證是選擇性的;不過,伺服器設定可能需要用戶端出示有效的憑證,做為初始連接協商的一部分。Client certificates are, by default, optional; however, the server configuration might require that the client present a valid certificate as part of the initial connection negotiation.

注意

架構會在建立 SSL 會話時加以快取,並嘗試針對新的要求重複使用快取會話(如果可能的話)。The Framework caches SSL sessions as they are created and attempts to reuse a cached session for a new request, if possible. 嘗試重複使用 SSL 會話時, ClientCertificates 如果有一個) ,架構會使用 (的第一個元素,如果是空的,則會嘗試重複使用匿名會話 ClientCertificatesWhen attempting to reuse an SSL session, the Framework uses the first element of ClientCertificates (if there is one), or tries to reuse an anonymous sessions if ClientCertificates is empty.

適用於