• DR-IT Software
  • Products
  • Documentation
  • Product page
  • Examples
  • API reference
  • Support
Show / Hide Table of Contents

Sign Message

Signs a MIME message with DKIM.

Code

using System.Security.Cryptography;
using DRIT.Mail.Rfc.Dkim;
using DRIT.Mail.Rfc.Mime;

// Load or build the message to sign
MimeMessage message = MimeMessage.Load("message.eml");

// Load the private key (RSA)
using var rsa = RSA.Create();
rsa.ImportFromPem(File.ReadAllText("private_key.pem"));

var options = new DkimSignerOptions
{
    Domain = "example.com",
    Selector = "default",
    SigningAlgorithm = DkimSigningAlgorithm.RsaSha256,
    HeaderCanonicalization = DkimCanonicalizationMode.Relaxed,
    BodyCanonicalization = DkimCanonicalizationMode.Relaxed,
    PrivateKey = rsa,
};

var signer = new DkimSigner(options);
signer.Sign(message);

// Write the signed message
message.Write("signed.eml");

Remarks

DkimSigner adds a DKIM-Signature header to the message as defined in RFC 6376. The selector and domain together form the public key lookup record (<selector>._domainkey.<domain>).

  • Improve this Doc
Back to top

DR-IT Software documentation

DR-IT Software · Products · Documentation index · Product page · Downloads · Support · Licensing

Generated by DocFX