0

I've recently implemented DKIM using Mailkit / Mimekit in a .net web project. Previously I was sending plain HTML emails, and everything was fine. Now that I'm preparing the message using 7 bit encoding I keep losing periods (full stops).

The only thing I can think of is that I'm falling foul of dot-stuffing (the periods are missing in the same place consistently) but I don't know how to approach this. It should be noted that the DKIM is failing in the client due to the content not matching (ie. the missing periods)

Reference to dot-stuffing (see second bullet point under 4.5.2): https://www.rfc-editor.org/rfc/rfc5321#section-4.5.2

Note: if I send the exact same email without DKIM using the signing function the content is 100% correct (nothing missing).

Can anyone offer any advice, or show me if I'm being a bit thick here?

Many thanks!

Public Sub DkimSign(ByRef message As MimeMessage)
    ...
    Dim signer = New DkimSigner(keyPath, dkimDomain, dkimSelector) With {.SignatureAlgorithm = DkimSignatureAlgorithm.RsaSha256}
    message.Prepare(EncodingConstraint.SevenBit)
    message.Sign(signer, headers, headerAlgorithm, bodyAlgorithm)

End Sub
Community
  • 1
  • 1
Aron
  • 3
  • 1
  • dot-stuffing has nothing to do with DKIM signing. If you are dot-stuffing, you are doing it wrong. dot-stuffing is something ONLY SMTP should worry about. – jstedfast Feb 22 '18 at 21:26
  • I'm not doing anything apart from preparing the message from valid html content. The clients tested, be it outlook, hotmail or gmail, are removing periods in consistent locations. The source html contains it, the message is signed with the full stops in, but the client is removing it causing the DKIM to fail, and £30.00 (for example) to become £3000. dot-stuffing was the only thing I could think of, however if you can think of any other reason I'd be grateful! – Aron Feb 23 '18 at 10:52
  • What are you using to send the message? – jstedfast Feb 23 '18 at 11:52
  • The HTML is generated by our own system (built on vb.net 4.0). We then use Mailkit to compile the message as a MimeMessage, adding in sender, subject, recipients. the HTML is set as BodyBuilder's HtmlBody, then added to the MimeMessage using ToMessageBody. Once the MimeMessage is ready it's written to a physical file using WriteToPath into the pickup directory on the server. It is sent using the standard Microsoft SMTP server (the one that comes as standard and is accessed via IIS6) – Aron Feb 23 '18 at 13:59
  • To follow up on this, I dropped the physical file into a different folder so I could grab it, opened it up in a text editor and searched for the point where the period is missing. As I originally suspected the line begins with a period, which according to the rfc mentioned previously means the client will strip content following it. If I pre-convert any periods to html codes do you think this would get around it? See link for snip of email content, row higlighted. [link](https://drive.google.com/open?id=1vr4K9hZDfIQvvis-V5umRfwD-9Xrmhh8) – Aron Feb 23 '18 at 16:47
  • So this sounds like a problem with the Exchange pickup mechanism expecting dot stuffed files? If so, just dot stuff the output of MimeMessage.WriteTo(). Look at MailKits SmtpDataFilter to see how to do that. – jstedfast Feb 23 '18 at 23:57
  • or sure, html encode the periods will work too. – jstedfast Feb 24 '18 at 00:56

0 Answers0