.NET MailMessage 和 AlternativeViews 中的 DKIM
我正在使用 DKIM.NET (https://github.com/dmcgiv/DKIM.Net) 对 MailMessage 进行签名,然后再将其发送给收件人。我面临的问题是,当我以 HTML 和纯文本形式以 AlternativeViews 的形式插入内容时,上面的组件对 MailMessage 的正文 (mailMessage.Body) 进行了签名。
结果是我的 mailMessage.Body 为空,但收到的邮件正文包含我的替代视图,因此 DKIM 无法正确验证。
有什么办法可以解决这个问题吗?也许在将 HTML 和纯文本替代视图分配给 MailMessage 对象之前对其进行签名?或者也许使用另一个组件?
编辑:
自从我开始这个问题以来,我在 https:// 创建了一个项目github.com/yannispsarras/DKIM-AlternativeViews - 这绝不是完整或稳定的,但我将其发布在这里,以防任何人在 .NET 中寻找签名替代视图的解决方案时有任何用处。
I am using DKIM.NET (https://github.com/dmcgiv/DKIM.Net) to sign a MailMessage before sending it to a recipient. The problem i am facing is that the component above signs MailMessage's Body (mailMessage.Body) while I am inserting content as both HTML and plain text in the form of AlternativeViews.
The result is that my mailMessage.Body is null but the received messsage's body contains my alternative views therefore DKIM does not verify correctly.
Is there any way to resolve this problem? Maybe sign the HTML and Plain text alternative views before assigning them to the MailMessage object? Or maybe using another component?
EDIT:
Since I started this question I 've created a project at https://github.com/yannispsarras/DKIM-AlternativeViews - This is by no means complete or stable but I m posting it here in case its of any use to anyone looking to find a solution for signed alternative views in .NET.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我在开源的 MimeKit 中添加了对生成和验证 DKIM 签名的全面支持(许可证:MIT)并且完全免费用于商业用途。
如果您还需要 SMTP、POP3 和/或 IMAP 支持,请查看 MailKit,它构建于MimeKit。
由于 MimeKit 和 MailKit 在每次写入流时不会生成一组新的边界字符串,因此它们不会遇到使用 System.Net.Mail 和 DKIM.Net[1](不是 DKIM.Net 的错误,要明确)。
要在 MimeKit 中向邮件添加 DKIM 签名,您需要执行以下操作:
要使用 MailKit 发送邮件,您需要执行以下操作:
注意:
I've added full support for generating and verifying DKIM signatures in MimeKit which is open source (License: MIT) and completely free for commercial use.
If you also need SMTP, POP3, and/or IMAP support, check out MailKit which is built on top of MimeKit.
Since MimeKit and MailKit do not generate a new set of boundary strings each time they are written to a stream, they do not suffer from the problems you will face using System.Net.Mail and DKIM.Net[1] (not DKIM.Net's fault, to be clear).
To add a DKIM signature to a message in MimeKit, you would do something like this:
To send the message using MailKit, you would do something like this:
Notes:
您可以尝试 Mail.dll 电子邮件组件,它支持 DKIM,包括:签名和验证:
http://www.limilabs.com/blog/sign-emails-with-dkim
http://www.limilabs.com/blog/sign-emails-with-dkim 不过,该组件不是免费的,请注意它是我写的。
You can try Mail.dll email component it supports DKIM, both: signing and validation:
http://www.limilabs.com/blog/sign-emails-with-dkim
The component is not free however, please also note that I wrote it.
我已更新 DKIM.Net 网站上的自述文件来解释此限制。这基本上是由于 System.Net.Mail.SmtpClient 生成边界来分隔替代视图或附件的方式 - 它们是新的 Guid,因此每次发送消息时边界 ID 都会发生变化 - 如果内容发生变化,则签名失败。该代码攻击 SmptClient,通过使用虚拟流发送 MailMessage 来获取电子邮件的完整内容。
I've updated the read me on the DKIM.Net site to explain this limitation. It's basically due to the way System.Net.Mail.SmtpClient generates boundaries to seperate alternative views or attachments - they are new Guids so each time the message is sent the boundary id changes - if the content changes then the signing fails. The code hacks SmptClient to get the full content of the email by Sending the MailMessage using a dummy stream.