Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

DomainKeys Identified Mail (DKIM) and DomainKey email signing for .Net (C#)

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 libs
Octocat-spinner-32 src add support for multiple version of MailMessage internal Send method
Octocat-spinner-32 changelog.txt
Octocat-spinner-32 readme.md
readme.md

DKIM.Net

DomainKeys Identified Mail (DKIM) and Domain Key email signing for .Net Framework

Known Issues

As System.Net.Mail.SmtpClient generates boundary identifiers randomly and as this code hacks the SmtpClient to retrieve the full email content before sending the code cannot be used when sending with SmtpClient and the MailMessage when the MailMessage has an alternative view or an attachment.

Example - Sending with SmtpClient

    var msg = new MailMessage();

    msg.From = new MailAddress("me@mydomain.com", "Joe Bloggs");
    msg.To.Add(new MailAddress("check-auth@verifier.port25.com", "Port25"));
    msg.Subject = "Testing DKIM.Net";
    msg.Body = "Hello World";




    var privateKey = PrivateKeySigner.Create(@"-----BEGIN RSA PRIVATE KEY-----
    ....
    -----END RSA PRIVATE KEY-----");



    var domainKeySigner = new DomainKeySigner(privateKey, "mydomain.com", "abc", new string[] { "From", "To", "Subject" });
    msg.DomainKeySign(domainKeySigner);


    var dkimSigner = new DkimSigner(privateKey, "mydomain.com", "abc", new string[] { "From", "To", "Subject" });
    msg.DkimSign(dkimSigner);

    new SmtpClient().Send(msg);

Example - DNS Records

Domain Key settings

_domainkey "o=~;r=admin@mydomain.com"

Domain Key / DKIM selector

selector._domainkey "k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDetWmczoNly/wfDc5WH8F2o42kGjYG7bbmfxjNP2y2qZja84v5W8z8SL702w3N5ZwQLdQmuQ8yN4WOYrg8DHGOB6g+xVP3h1Hr1+C05Vk/x3BXw0wIffNqcVzPkRNNNILtiwPJhhlDVMvaTx20vrrCAz9i6CX6Onj4OWxUaAjtuQIDAQAB"
Something went wrong with that request. Please try again.