ComponentPro UltimateMail

Creating an encrypted mail message

Language Filter: AllSend comments on this topic to ComponentPro

To encrypt a mail message, you only need an X509 certificate (private key is not required). Certificate can be loaded from a certificate file (.cer or .der extensions), from a PKCS#12 encrypted file (.pfx or .p12 extensions), or get it from the Window Certificate Store.

Only the message body is encrypted, the top-level headers are not encrypted.The example below shows how to encrypt a mail message.
using System;
using System.Security.Cryptography.X509Certificates;
using ComponentPro.Net.Mail;


// Create a new instance of the MailMessage class.
MailMessage msg = new MailMessage();

msg.Subject = "Hello";
msg.BodyText = "How are you?";

// Load a certificate file and encrypt the message.
msg.Encrypt(new X509Certificate2("mycert.cer", "mypassword"));