DomainKeys Identified Mail (DKIM) library for .Net C#

I've just committed code that I've been working on for a couple of evenings that enables you to DKIM sign System.Net.Mail.MailMessage objects and send DKIM signed emails. Ideally you should sign emails at the last possible stage, perhaps by your mail server, as if your mail server alters certain headers or the body it could make the signing invalid but in some cases it's not possible. I was working on adding DKIM signing to Amazon's Simple Email Server (SES) SendRawEmail service and decided to refractor the code into it's own library.

The code currently has a dependency on Bouncy Castle Cryptography API which is used to calculate the SHA256 signature but I plan to remove this once I get it working with my own code.

You can download the code at https://github.com/dmcgiv/DKIM.Net


 

Published 02 May 2011 22:28 by Damien McGivern
Filed under:

Comments

# re: DomainKeys Identified Mail (DKIM) library for .Net C#

04 July 2011 20:37 by David Carroll

Hi Damien, Have you been successful at using your DKIM.Net library to sign for sending with SES SendRawEmail? Your code looks great, but I keep getting a Body hash did not verify error.

# re: DomainKeys Identified Mail (DKIM) library for .Net C#

12 August 2011 16:08 by Jeff

same comments as the commenter above. Please help

# re: DomainKeys Identified Mail (DKIM) library for .Net C#

16 August 2011 17:02 by samv

Damien - great code! Do you allow this code to be used under any particular license type?

# re: DomainKeys Identified Mail (DKIM) library for .Net C#

28 September 2011 21:11 by Eric

I was able to get this to work with Amazon SES.  Please note that you will have to use SendRawEmail and not SendEmail to get this to work.  However, signing does not work properly if you use Alternative Views (html and text, etc) in your message.  I presume that Damien's code fails to hash this properly but haven't dug any deeper.

# re: DomainKeys Identified Mail (DKIM) library for .Net C#

08 November 2011 22:27 by Damien McGivern

@Eric the code doesn't work for MailMessage objects if there are alternative views or attachments because SmtpClient randomly generates the boundary tags the content will never be correct and so fail. The only way around this is to use another SMTP client other then the one that comes with .Net.