SmtpClient.ClientCertificates 属性


指定应该使用哪些证书来建立安全套接字层 (SSL) 连接。Specify which certificates should be used to establish the Secure Sockets Layer (SSL) connection.

 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,包含一个或多个客户端证书。An X509CertificateCollection, holding one or more client certificates. 默认值从配置文件中的邮件配置特性导出。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 = "";
    string from = "";
    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 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 的第一个元素(如果有),或在 ClientCertificates 为空时尝试重用匿名会话。When 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.