MailAddress.Certificate Property


Gets or sets the associating digital certificate for digital signature and encryption (S/MIME). This property is obsoleted, use MailAddress.Certificate2 property instead.

[Visual Basic]
Public Property Certificate As Certificate
[C#]
public Certificate Certificate {get; set;}
[C++]
public: __property Certificate^ get_Certificate();
public: __property void set_Certificate(Certificate^);
[JScript]
public function get Certificate() : Certificate;
public function set Certificate(Certificate);

Property Value

A Certificate value indicating the associating digital certificate.

Remarks

By default, Personal digital certificate is stored at Certificate.CertificateStoreLocation.CERT_SYSTEM_STORE_CURRENT_USER "my". Encryption digital certificates are stored at Certificate.CertificateStoreLocation.CERT_SYSTEM_STORE_CURRENT_USER "Address Book". If you want to search certificate in Windows Active Directory, please use Certificate.CertificateStoreLocation.CERT_STORE_PROV_LDAP_STORE and input LDAP query statement in storeName parameter.
To learn more about email digital signature and encryption, please refer to Digital Signature and E-mail Encryption section.

RSASSA-PSS Signature and RSA-OAEP Encryption

If you need to use RSASSA-PSS signature scheme, you need a special version of EASendMail, please have a look at this topic:
RSASSA-PSS + RSA-OAEP Encryption with SHA256

Example

[Visual Basic, C#] The following example demonstrates how to load certificate to sign email content with EASendMail SMTP Component. To get the full samples of EASendMail, please refer to Samples section.

[VB - Sign Email with Certificate]

Try
    Dim oMail As SmtpMail = New SmtpMail("TryIt")
    oMail.From = New MailAddress("test@emailarchitect.net")

    ' Find certificate by email adddress in My Personal Store. 
    ' The certificate can be imported by *.pfx file like this: 
    ' oMail.From.Certificate.Load("c:\test.pfx", "pfxpassword", Certificate.CertificateKeyLocation.CRYPT_USER_KEYSET) 
    ' Once the certificate is loaded to From, the email content will be signed automatically

    oMail.From.Certificate.FindSubject(oMail.From.Address,
        Certificate.CertificateStoreLocation.CERT_SYSTEM_STORE_CURRENT_USER,
        "My")

Catch exp As Exception
    Console.WriteLine("No sign certificate found for sender email: {0}", exp.Message)
End Try


[C# - Sign Email with Certificate] try { SmtpMail oMail = new SmtpMail("TryIt"); oMail.From = "test@adminsystem.com"; // Find certificate by email adddress in My Personal Store. // The certificate can be also imported by *.pfx file like this: // oMail.From.Certificate.Load("c:\\test.pfx", "pfxpassword", Certificate.CertificateKeyLocation.CRYPT_USER_KEYSET); // Once the certificate is loaded to From, the email content will be signed automatically oMail.From.Certificate.FindSubject(oMail.From.Address, Certificate.CertificateStoreLocation.CERT_SYSTEM_STORE_CURRENT_USER, "My"); } catch (Exception exp) { Console.WriteLine("No sign certificate found {0}", exp.Message); }
[VB - Encrypt Email] Dim oMail As SmtpMail = New SmtpMail("TryIt") oMail.From = New MailAddress("test@adminsystem.com") oMail.To = New AddressCollection("encrypt1@adminsystem.com, encrypt2@adminsystem.com") For i As Integer = 0 To oMail.To.Count - 1 Dim recipient As MailAddress = oMail.To(i) Try ' Find certificate by email adddress in My Other Peoples Store. ' The certificate can be imported by *.cer file like this: ' recipient.Certificate.Load("c:\encrypt1.cer") ' Once the certificate Is loaded to MailAddress, the email content will be encrypted automatically recipient.Certificate.FindSubject(recipient.Address, Certificate.CertificateStoreLocation.CERT_SYSTEM_STORE_CURRENT_USER, "AddressBook") Catch Try ' No certificate found in AddressBook, lookup it in My recipient.Certificate.FindSubject(recipient.Address, Certificate.CertificateStoreLocation.CERT_SYSTEM_STORE_CURRENT_USER, "My") Catch ex As Exception Console.WriteLine("No encryption certificate found for {0} - {1}", recipient.Address, ex.Message) End Try End Try Next
[C# - Encrypt Email] SmtpMail oMail = new SmtpMail("TryIt"); oMail.From = "test@adminsystem.com"; oMail.To = "encrypt1@adminsystem.com, encrypt2@adminsystem.com"; for (int i = 0; i < oMail.To.Count; i++) { MailAddress recipient = oMail.To[i] as MailAddress; try { // Find certificate by email adddress in My Other Peoples Store. // The certificate can be also imported by *.cer file like this: // recipient.Certificate.Load("c:\\encrypt1.cer"); // Once the certificate is loaded to MailAddress, the email content will be encrypted automatically recipient.Certificate.FindSubject(recipient.Address, Certificate.CertificateStoreLocation.CERT_SYSTEM_STORE_CURRENT_USER, "AddressBook"); } catch { try { // No certificate found in AddressBook, lookup it in My recipient.Certificate.FindSubject(recipient.Address, Certificate.CertificateStoreLocation.CERT_SYSTEM_STORE_CURRENT_USER, "My"); } catch (Exception exp) { Console.WriteLine("No encryption certificate found for {0} - {1}", recipient.Address, exp.Message); } } }
[VB - Find Certificate in Active Directory by LDAP] Dim oMail As SmtpMail = New SmtpMail("TryIt") oMail.From = New MailAddress("test@adminsystem.com") oMail.To = New AddressCollection("Encryptor <encrypt@adminsystem.com>") For i As Integer = 0 To oMail.To.Count - 1 Dim recipient As MailAddress = oMail.To(i) Try ' Please change the ldap path as your environment. recipient.Certificate.FindSubject(recipient.Address, Certificate.CertificateStoreLocation.CERT_STORE_PROV_LDAP_STORE, String.Format("ldap:///CN={0},CN=USERS,DC=my,DC=server?userCertificate", recipient.Name)) Catch exp As Exception Console.WriteLine("No encryption certificate found for {0} - {1}", recipient.Address, exp.Message) End Try Next
[C# - Find Certificate in Active Directory by LDAP] SmtpMail oMail = new SmtpMail("TryIt"); oMail.From = "test@adminsystem.com"; oMail.To = "Encryptor <encrypt@adminsystem.com>"; for (int i = 0; i < oMail.To.Count; i++) { MailAddress recipient = oMail.To[i] as MailAddress; try { // Please change the ldap path as your environment. recipient.Certificate.FindSubject(recipient.Address, Certificate.CertificateStoreLocation.CERT_STORE_PROV_LDAP_STORE, String.Format("ldap:///CN={0},CN=USERS,DC=my,DC=server?userCertificate", recipient.Name)); } catch (Exception exp) { Console.WriteLine("No encryption certificate found for {0} - {1}", recipient.Address, exp.Message); } }

See Also

From, ReplyTo, Sender and Return-Path
SmtpMail.From Property
SmtpMail.ReplyTo Property
SmtpMail.Sender Property
SmtpMail.ReturnPath Property
SmtpMail.To Property
SmtpMail.Cc Property
SmtpMail.Bcc Property

Online Examples

Sign Email - VB
Encrypt Email - VB
Sign Email - C#
Encrypt Email - C#
Sign Email - C++/CLI
Encrypt Email - C++/CLI