We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Handling Signed/Encrypted emails with Aspose.Email

I have some signed and/or encrypted (S/MIME) emails in MSG files and PSTs which I would like to open and read as MapiMessage instances. I have access to PFX files (certificates and private keys) used to sign/encrypt the emails.

Are there examples or information about how to achieve this? There is some basic information at https://docs.aspose.com/email/net/utility-features-mailmessage/#encrypting-and-decrypting-messages but that doesn’t cover using the MapiMessage class and doesn’t seem to cover Signed emails.

For example, from some experimentation it seems to me like the MailMessage.Decrypt(X509Certificate2) method is used to decrypt encrypted MailMessage instances, and the MailMessage.Decrypt() method is used to “decrypt” signed instances. Is that correct?

Converting from one of the resulting MailMessage instances to a MapiMessage using MapiMessage.FromMailMessage(message) seems to result in a MapiMessage that is missing information though, such as the Body.


Hi Reuben,

Thank you for writing to Aspose support team.

Following is a sample code which describes all the steps to sign, encrypt, decrypt and remove signature from a message using certificate. Please give it a try and let us know the feedback.

string publicCertFile = @“sample.cer”;<o:p></o:p>

string privateCertFile = @"sample.pfx";

X509Certificate2 publicCert = new X509Certificate2(publicCertFile);

X509Certificate2 privateCert = new X509Certificate2(privateCertFile, "password");

MailMessage msg = new MailMessage("userfrom@gmail.com", "userto@gmail.com", "Signed message only", "Test Body of signed message");

MailMessage signed = msg.AttachSignature(privateCert);

MailMessage encrypted = signed.Encrypt(publicCert);

MailMessage decrypted = encrypted.Decrypt(privateCert);

MailMessage unsigned = decrypted.RemoveSignature();//The original message with proper body

MapiMessage mapi = MapiMessage.FromMailMessage(unsigned);

Thanks, that helped.

Hi Reuben,

Thank you for providing the feedback.