Mail.IsEncrypted Property


Gets whether the email is encrypted by digital certificate.

[Visual Basic]
Public Property IsEncrypted As Boolean
[C#]
public bool IsEncrypted {get;}
[C++]
public: __property bool get_IsEncrypted();
[JScript]
public function get IsEncrypted() : Boolean;

Property Value

A bool value indicating whether the email is encrypted by digital certificate.

Example

[Visual Basic, C#, C++] The following example demonstrates how to verify signed email and decrypt encrypted email with EAGetMail POP3 & IMAP4 Component. To get the full samples of EAGetMail, please refer to Samples section.

[VB - Verify and Decrypt Email]
Dim oMail As New Mail("TryIt")
oMail.Load("c:\test.eml, False)

If (oMail.IsEncrypted) Then
    Try
        ' this email is encrypted, we decrypt it by user default certificate.
        ' you can also use specified certificate like this
        ' Dim oCert As New Certificate()
        ' oCert.Load("c:\test.pfx", "pfxpassword", Certificate.CertificateKeyLocation.CRYPT_USER_KEYSET)
        ' oMail = oMail.Decrypt(oCert)
        oMail = oMail.Decrypt(Nothing)
    Catch ep As Exception
        MessageBox.Show(ep.Message)
    End Try
End If

If (oMail.IsSigned) Then
    Try
        ' this email is digital signed.
        Dim cert As EAGetMail.Certificate = oMail.VerifySignature()
        MessageBox.Show("This email contains a valid digital signature.")
        ' you can add the certificate to your certificate storage like this
        ' cert.AddToStore(Certificate.CertificateStoreLocation.CERT_SYSTEM_STORE_CURRENT_USER,"addressbook");
        ' then you can use send the encrypted email back to this sender.
    Catch ep As Exception
        MessageBox.Show(ep.Message)
    End Try
End If


[C# - Verify and Decrypt Email] Mail oMail = new Mail("TryIt"); oMail.Load("c:\\test.eml", false); if(oMail.IsEncrypted) { try { // this email is encrypted, we decrypt it by user default certificate. // you can also use specified certificate like this // Certificate oCert = new Certificate(); // oCert.Load("c:\test.pfx", "pfxpassword", Certificate.CertificateKeyLocation.CRYPT_USER_KEYSET) // oMail = oMail.Decrypt(oCert); oMail = oMail.Decrypt(null); } catch(Exception ep) { MessageBox.Show(ep.Message); } } if(oMail.IsSigned) { try { // this email is digital signed. EAGetMail.Certificate cert = oMail.VerifySignature(); MessageBox.Show("This email contains a valid digital signature."); // you can add the certificate to your certificate storage like this // cert.AddToStore(Certificate.CertificateStoreLocation.CERT_SYSTEM_STORE_CURRENT_USER, // "addressbook"); // then you can use send the encrypted email back to this sender. } catch(Exception ep) { MessageBox.Show(ep.Message); } }

Remarks

To learn more about email digital signature and encryption, please refer to Digital Signature and E-mail Encryption/Decryption section.

See Also

Mail.IsSigned Property
Mail.VerifySignature Method
Mail.Decrypt Method

Online Tutorials

Verify Digital Signature and Decrypt Email in C# - Tutorial
Verify Digital Signature and Decrypt Email in VB.NET - Tutorial
Verify Digital Signature and Decrypt Email in C++/CLI - Tutorial