MailMessage.Encrypt

Encrypt(X509Certificate2)

Encrypts this message

public virtual MailMessage Encrypt(X509Certificate2 certificate)
ParameterTypeDescription
certificateX509Certificate2X509 certificate to encrypt message

Return Value

Encrypted email message

Examples

The following example shows how to encrypt Messages

[C#]

var publicCertFile = "MartinCertificate.cer";
var publicCert = new X509Certificate2(publicCertFile);

// Create a message
var eml = new MailMessage
{
    From = "atneostthaecrcount@gmail.com",
    To = "atneostthaecrcount@gmail.com",
    Subject = "Test subject",
    Body = "Test Body"
};

// Encrypt the message
var encryptedEml = eml.Encrypt(publicCert);
Console.WriteLine(encryptedEml.IsEncrypted ? "Its encrypted" : "Its NOT encrypted");

[Visual Basic]

Dim publicCertFile = "MartinCertificate.cer"
    Dim publicCert = New X509Certificate2(publicCertFile)

' Create a message
    Dim eml = New MailMessage With {
        .From = "atneostthaecrcount@gmail.com",
        .[To] = "atneostthaecrcount@gmail.com",
        .Subject = "Test subject",
        .Body = "Test Body"
    }

' Encrypt the message
    Dim encryptedEml = eml.Encrypt(publicCert)
    Console.WriteLine(If(encryptedEml.IsEncrypted, "Its encrypted", "Its NOT encrypted"))

See Also


Encrypt(X509Certificate2[])

Encrypts this message

public virtual MailMessage Encrypt(X509Certificate2[] certificates)
ParameterTypeDescription
certificatesX509Certificate2[]Array with X509 certificates to encrypt message

Return Value

Encrypted email message

See Also