SmtpClient.ClientCertificates Egenskap

Definition

Ange vilka certifikat som ska användas för att upprätta SSL-anslutningen (Secure Sockets Layer).

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

Egenskapsvärde

Ett X509CertificateCollection, som innehåller ett eller flera klientcertifikat. Standardvärdet härleds från e-postkonfigurationsattributen i en konfigurationsfil.

Exempel

I följande kodexempel upprättas en SSL-anslutning med SMTP-servern och anslutningen används för att skicka ett e-postmeddelande.

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

Kommentarer

Klientcertifikat är som standard valfria. Serverkonfigurationen kan dock kräva att klienten presenterar ett giltigt certifikat som en del av den inledande anslutningsförhandlingen.

Note

Framework cachelagrar SSL-sessioner när de skapas och försöker återanvända en cachelagrad session för en ny begäran, om möjligt. När du försöker återanvända en SSL-session använder ramverket det första elementet ClientCertificates i (om det finns en) eller försöker återanvända en anonym session om ClientCertificates den är tom.

Gäller för

Se även