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);
}
注解
默认情况下,客户端证书是可选的;但是,服务器配置可能需要客户端在初始连接协商过程中提供有效的证书。
注释
框架在创建 SSL 会话时缓存 SSL 会话,并尝试尽可能为新请求重复使用缓存会话。 尝试重复使用 SSL 会话时,框架使用第一个元素 ClientCertificates (如果有),或者尝试重复使用匿名会话(如果 ClientCertificates 为空)。