0 votes

I have a question regarding encrypted mails (or more precise, mail files). I try to read those files on the server while preparing to archive them. I don't have a certificate to derypt the file and that's not the purpose, I just want to read all that's available. In case of an encrypted mail, just header data is perfect.

I generate the mail message as follows:

_message = new Limilabs.Mail.MailBuilder()

In case of my encrypted sample mail, it throws the following exception:

System.Security.Cryptography.CryptographicException: Die Nachricht mit verschachtelten Daten enthält nicht den angegebenen Empfänger.

Can anything be done to obtain a valid message and see whether the mail is encrypted or not, so in this case I would not look for attachments and/or body contents.

Thanks and best regards,

edited by

1 Answer

0 votes
Best answer

By default Mail.dll tries to decrypt messages using certificates installed in windows certificate store.

To avoid automatic message decryption use MailBuilder.SMIMEConfiguration.DecryptAutomatically and MailBuilder.SMIMEConfiguration.ExtractSignedAutomatically properties:

var builder = new Limilabs.Mail.MailBuilder();
builder.SMIMEConfiguration.DecryptAutomatically = false;
builder.SMIMEConfiguration.ExtractSignedAutomatically= false;
var message = builder.CreateFromEmlFile( plainMimeSourceFile );

Later you can check IMail.NeedsDecryption or IMail.IsEncrypted,
and IMail.NeedsSignedExtraction or IMail.IsSigned properties:

  • IMail.IsEncrypted - indicates if this email message has been encrypted.
  • IMail.NeedsDecryption - indicates if this email message needs to be decrypted (You can use IMail.Decrypt(),IMail.Decrypt(List), IMail.Decrypt(X509Certificate2) to decrypt a message).
by (298k points)