SmtpClient.ClientCertificates 属性

定义

指定应该使用哪些证书来建立安全套接字层 (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);
}

注解

默认情况下,客户端证书是可选的;但是,服务器配置可能要求客户端提供有效的证书作为初始连接协商的一部分。

注意

框架在创建 SSL 会话时缓存这些会话,并尝试为新请求重复使用缓存的会话(如果可能)。 尝试重用 SSL 会话时,如果存在一个) ,框架将使用 (的第一个元素 ClientCertificates ;如果 ClientCertificates 为空,则尝试重用匿名会话。

适用于

另请参阅