+2 votes

Hello, I've found in the Forum the opposite question, how to send encrypted and digitally signed emails. I need to be able to receive encrypted and digitally signed emails.

Is it possible (if yes, how?) with Mail.dll by using IMAP?

The full use case:

  • I'm currently using IMAP
  • Check first whether an email is coming from an expected valid sender, for this purpose the email shall be encrypted and digitally signed.
  • If yes, continue reading the email

Thanks in advance for any help.
Emilio

by

1 Answer

+1 vote

Generally it is all done automatically. If an email is encrypted, it is decrypted during parsing (MailBuilder.CreateFromEml). Of course you need to have proper certificates installed on your machine (StoreName.My certificate store).

To validate SMIME signature use IMail.CheckSignature method:

using (Imap imap = new Imap())
{
    imap.Connect("imap.example.com"); // or ConnectSSL
    imap.UseBestLogin("user", "password");

    MailBuilder builder = new MailBuilder();
    foreach (long uid in imap.GetAll())
    {
        IMail email = builder.CreateFromEml(
            imap.GetMessageByUID(uid));

        // Check signature
        if (email.IsSigned == true)
            email.CheckSignature(true);
    }
    imap.Close();
}

Below you can find detailed articles on this subject. They explain how to disable automatic decryption and how to use specific certificates for decryption.

Decrypt S/MIME emails:
https://www.limilabs.com/blog/decrypt-smime-emails

Validate S/MIME signed emails:
https://www.limilabs.com/blog/validate-smime-emails

by (301k points)
...