ComponentPro UltimateBounceInspector

      CertificateReceived Event

      See AlsoMembers Options: Show AllLanguage Filter: AllSend comments on this topic to ComponentPro
      Occurs when a POP3 server's certificate was received and verified.

      Syntax

      public event EventHandler<TEventArgs> CertificateReceived

      Examples

      Show how to handle the CertificateReceived event.

      using System;
      using System.Security.Cryptography.X509Certificates;
      using System.Text;
      using ComponentPro.Net;
      using ComponentPro.Net.Mail;
      using ComponentPro.Security.Certificates;
      
      ...
      
      public void HandleCertificateReceivedEvent()
      {
          // Create a new instance. 
          Pop3 client = new Pop3();
      
          client.CertificateReceived += client_CertificateReceived;
      
          // Connect to the POP3 server. 
          client.Connect("myserver", 110, SslSecurityMode.Explicit);
      
          // Authenticate. 
          client.Authenticate("userName", "password");
      
          // Do something here... 
          // ... 
          
      
          // Disconnect. 
          client.Disconnect();
      }
      
      /// <summary> 
      /// Returns all issues of the given certificate. 
      /// </summary> 
      /// <param name="status">The certificate verification result.</param> 
      /// <param name="code">The error code.</param> 
      /// <returns>Certificate problems.</returns> 
      private static string GetCertProblem(CertificateVerificationStatus status, int code)
      {
          switch (status)
          {
              case CertificateVerificationStatus.TimeNotValid:
                  return "Server's certificate has expired or is not valid yet.";
      
              case CertificateVerificationStatus.Revoked:
                  return "Server's certificate has been revoked.";
      
              case CertificateVerificationStatus.UnknownCa:
                  return "Server's certificate was issued by an unknown authority.";
      
              case CertificateVerificationStatus.UntrustedRoot:
                  return "Server's certificate was issued by an untrusted authority.";
      
              case CertificateVerificationStatus.IncompleteChain:
                  return "Server's certificate does not chain up to a trusted root authority.";
      
              case CertificateVerificationStatus.Malformed:
                  return "Server's certificate is malformed.";
      
              case CertificateVerificationStatus.CnNotMatch:
                  return "Server hostname does not match the certificate.";
      
              case CertificateVerificationStatus.UnknownError:
                  return string.Format("Error {0:x} encountered while validating server's certificate.", code);
      
              default:
                  return status.ToString();
          }
      }
      
      void client_CertificateReceived(object sender, ComponentPro.Security.CertificateReceivedEventArgs e)
      {
          X509Certificate2 cert = e.ServerCertificates[0];
      
          CertificateVerificationStatus status = e.Status;
      
          CertificateVerificationStatus[] values = (CertificateVerificationStatus[])Enum.GetValues(typeof(CertificateVerificationStatus));
      
          StringBuilder sbIssues = new StringBuilder();
          for (int i = 0; i < values.Length; i++)
          {
              // Matches the validation status? 
              if ((status & values[i]) == 0)
                  continue;
      
              // The issue is processed. 
              status ^= values[i];
      
              sbIssues.AppendFormat("{0}\r\n", GetCertProblem(values[i], e.ErrorCode));
          }
      
          Console.WriteLine("Issue: " + sbIssues.ToString());
      
          Console.WriteLine("Subject: " + cert.SubjectName.Name);
          Console.WriteLine("Issuer: " + cert.IssuerName.Name);
          Console.WriteLine("Effective Date: " + cert.NotBefore);
          Console.WriteLine("Expiry Date: " + cert.NotAfter);
          Console.ResetColor();
          Console.Write("Do you want to accept this certificate (Add to trusted list, Yes, No) [a,y,n]?");
      
          string response = Console.ReadLine().Trim().ToLower();
      
          // Add certiticate of the issuer CA to the trusted list. 
          if (response == "a")
          {
              e.AddToTrustedRoot = true;
          }
          else if (response == "y")
          {
              e.Accept = true;
          }
      }

      Framework

      .NET Compact Framework.NET Compact Framework

      Supported version: 2.0, 3.5, and 3.9
      Assembly: ComponentPro.Mail.CF (in ComponentPro.Mail.CF.dll)

      .NET Framework.NET Framework

      Supported version: 2.0, 3.0, 3.5, 4.0, 4.5.x, 4.6.x and later
      Assembly: ComponentPro.Mail (in ComponentPro.Mail.dll)

      Xamarin AndroidXamarin Android

      Supported version: 2.3 and later
      Assembly: ComponentPro.Mail.Android (in ComponentPro.Mail.Android.dll)

      Xamarin MacXamarin Mac

      Supported version: 2.0.x and later
      Assembly: ComponentPro.Mail.Mac (in ComponentPro.Mail.Mac.dll)

      Xamarin iOSXamarin iOS

      Supported version: 5.1.x and later
      Assembly: ComponentPro.Mail.iOS (in ComponentPro.Mail.iOS.dll)

      See Also