Send signed email using S/MIME (SHA‑512)

In many cases it is required to use better that standard signing algorithms. With Mail.dll it is easy to specify algorithm that is used for signing. In this article we’ll show how to send S/MIME signed email using Mail.dll email component and specific signature algorithm (SHA-512).

If you don’t need to specify signature algorithm you can lean on default values: send signed email using S/MIME.

Signature algorithm selection is done through Algorithm property of the SignatureConfiguration class. You can use CommonOids class static properties to retrieve common oids (object identifiers): Sha1, Sha256, Sha512.

Signing using fluent interface

IMail mail = Mail.Text("text")
    .SignWith(new SignatureConfiguration(new X509Certificate2(...)) 
            Algorithm = CommonOids.Sha512

Signing using MailBuilder

MailBuilder builder = new MailBuilder();
builder.Text = "text";
builder.From.Add(new MailBox(""));
builder.SignWith(new SignatureConfiguration(certificate) 
        Algorithm = CommonOids.Sha512
IMail mail = builder.Create();

Sending email using SMTP

Now we can connect to SMTP server and send the email we recently created:

using (Smtp client = new Smtp())
    client.Connect(""); // or ConnectSSL
    client.UseBestLogin("user", "password");

Tags: , , , ,


Consider using our Q&A forum for asking any questions.