PowerTCP Mail for .NET
Certificate Property
See Also  Send comments on this topic.
Dart.PowerTCP.Mail Namespace > Pop Class : Certificate Property




The Certificate object representing the certificate to use for optional client-side authentication.

Syntax

Visual Basic (Declaration) 
<BrowsableAttribute(False)>
<DescriptionAttribute("The Certificate used for optional client-side authentication")>
<DefaultValueAttribute()>
Public Property Certificate As Certificate
Visual Basic (Usage)Copy Code
Dim instance As Pop
Dim value As Certificate
 
instance.Certificate = value
 
value = instance.Certificate
C# 
[BrowsableAttribute(false)]
[DescriptionAttribute("The Certificate used for optional client-side authentication")]
[DefaultValueAttribute()]
public Certificate Certificate {get; set;}
Managed Extensions for C++ 
[BrowsableAttribute(false)]
[DescriptionAttribute("The Certificate used for optional client-side authentication")]
[DefaultValueAttribute()]
public: __property Certificate* get_Certificate();
public: __property void set_Certificate( 
   Certificate* value
);
C++/CLI 
[BrowsableAttribute(false)]
[DescriptionAttribute("The Certificate used for optional client-side authentication")]
[DefaultValueAttribute()]
public:
property Certificate^ Certificate {
   Certificate^ get();
   void set (    Certificate^ value);
}

Property Value

A Certificate object representing the certificate to use for optional client-side authentication; null otherwise.

Example

The following example demonstrates using POP over SSL.
Visual BasicCopy Code
' Be sure to import the namespace by putting "Imports Dart.PowerTCP.Mail"
' at the top of your class.

Private Sub PopSSLTest()

   ' Use explicit SSL
   Pop1.Security = Dart.PowerTCP.Mail.Security.Explicit;
   
   ' Automatically remove files after getting them from the server
   Pop1.AutoDelete = True

   ' Login. The default settings will cause the Pop component to
   ' automatically retrieve all messages, delete them from the
   ' server, and logout.
   Pop1.Login("mail.test.com", "testuser", "testpass")

   ' All message retrieved. Iterate through the collection
   ' and display data.
   Dim msg As PopMessage
   For Each msg In Pop1.Messages
      Debug.WriteLine("Message ID: " + msg.Id)
      Debug.WriteLine("Message UID: " + msg.Uid)
      Debug.WriteLine("Messge Size: " + msg.Size)
      Debug.WriteLine("From: " + msg.Message.From.Address)
      Debug.WriteLine("Subject: " + msg.Message.Subject)
   Next
End Sub

Private Sub Pop1_CertificateReceived(ByVal sender As Object, e As Dart.PowerTCP.Mail.CertificateReceivedEventArgs) Handles Pop1.CertificateReceived
   Dim msg As String = ""

   ' Check to see if the certificate is from a trusted root.
   If Not e.TrustedRoot Then
      msg += "This certificate is not from a trusted root" + vbCrLf
   End If

   ' Check to see if the certificate has a valid date.
   If Not e.ValidDate Then
      msg += "This certificate does not have a valid date" + vbCrLf
   End If

   ' Check to see if the certificate has a valid name.
   If Not e.ValidName Then
      msg += "This certificate does not have a valid name" + vbCrLf
   End If
   
   If msg <> "" Then
      msg += "Would you like to accept this certificate anyway?"
      If MessageBox.Show(msg, "Invalid Cert Received", MessageBoxButtons.YesNo) = DialogResult.Yes Then
         ' User wants to accept the invalid cert. Accept it.
         e.Accept = True
      End If
   End If
End Sub

Private Sub Pop1_CertificateRequested(ByVal sender As Object, e As EventArgs) Handles Pop1.CertificateRequested
   ' Create a new instance of CertificateListForm
   Dim certForm as new CertificateListForm(True, True)
   certForm.Text = "The Server Requested A Client Certificate"

   ' Show the CertificateListForm to the user and let them choose a certificate
   If certForm.ShowDialog() = DialogResult.OK Then
      ' Set the Certificate property to the certificate the user selected.
      Pop1.Certificate = certForm.SelectedCertificate
   Else
      MessageBox.Show("You must select a cert. SSL communication will fail.")
   End If
End Sub
C#Copy Code
// Be sure to import the namespace by putting "using Dart.PowerTCP.Mail;"
// at the top of your class.

private void PopSSLTest()
{
   // Use explicit SSL
   pop1.Security = Dart.PowerTCP.Mail.Security.Explicit;
   
   // Automatically remove files after getting them from the server
   pop1.AutoDelete = true;

   // Login. The default settings will cause the Pop component to
   // automatically retrieve all messages, delete them from the
   // server, and logout.
   pop1.Login("mail.test.com", "testuser", "testpass");

   // All message retrieved. Iterate through the collection
   // and display data.
   foreach(PopMessage msg in pop1.Messages)
   {
      Debug.WriteLine("Message ID: " + msg.Id);
      Debug.WriteLine("Message UID: " + msg.Uid);
      Debug.WriteLine("Messge Size: " + msg.Size);
      Debug.WriteLine("From: " + msg.Message.From.Address);
      Debug.WriteLine("Subject: " + msg.Message.Subject);
   } 
}

private void pop1_CertificateReceived(object sender, Dart.PowerTCP.Mail.CertificateReceivedEventArgs e)
{
   string msg = "";

   // Check to see if the certificate is from a trusted root.
   if(!e.TrustedRoot)
      msg+= "This certificate is not from a trusted root\n";

   // Check to see if the certificate has a valid date.
   if(!e.ValidDate)
      msg+= "This certificate does not have a valid date\n";

   // Check to see if the certificate has a valid name.
   if(!e.ValidName)
      msg+= "This certificate does not have a valid name\n";

   if(msg != "")
   {
      msg += "Would you like to accept this certificate anyway?";
      if(MessageBox.Show(msg, "Invalid Cert Received", MessageBoxButtons.YesNo) == DialogResult.Yes)
      {
         // User wants to accept the invalid cert. Accept it.
         e.Accept = true;
      }
   }
}

private void pop1_CertificateRequested(object sender, System.EventArgs e)
{
   // Create a new instance of CertificateListForm
   CertificateListForm certForm = new CertificateListForm(true, true);
   certForm.Text = "The Server Requested A Client Certificate";

   // Show the CertificateListForm to the user and let them choose a certificate
   if(certForm.ShowDialog() == DialogResult.OK)
   {
      // Set the Certificate property to the certificate the user selected.
      pop1.Certificate = certForm.SelectedCertificate;
   }
   else
   {
      MessageBox.Show("You must select a cert. SSL communication will fail.");
   }
}

Remarks

If a secure server requests a certificate from the client for client-authentication, the value of this property is sent to the server.

Typically this property can either be set before attempting to connect or from within the CertificateRequested event which is raised when the server requests a certificate from the client.

Requirements

Target Platforms: Microsoft .NET Framework 2.0

See Also

Documentation Version 3.2
© 2010 Dart Communications. All Rights Reserved.