dmcgiv / dkim.net Goto Github PK
View Code? Open in Web Editor NEWDomainKeys Identified Mail (DKIM) and DomainKey email signing for .Net (C#)
DomainKeys Identified Mail (DKIM) and DomainKey email signing for .Net (C#)
I cannot figure out what is wrong in my setting for DKIM. I need your help.
dkimpy-milter (1.2.2-1) is used for DKIM signature and verification.
Sanzo Miyazawa
Return-Path: [email protected]
Received: from mail01.SiriusCloud.jp (219.118.72.1) by verifier.port25.com id h2guq82p2toj for [email protected]; Sun, 4 Sep 2022
05:54:44 +0000 (envelope-from [email protected])
Authentication-Results: verifier.port25.com; spf=pass smtp.mailfrom=[email protected];
iprev=pass (matches mail01.SiriusCloud.jp) policy.iprev=219.118.72.1;
dkim=permerror reason="unsupported signature algorithm" ;
dkim=fail reason="signature doesn't verify"
Received: from smi72700k.sanzo.org (61-213-47-254.catv296.ne.jp [61.213.47.254])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
(No client certificate requested)
(Authenticated sender: [email protected])
by access01.SiriusCloud.jp (Postfix) with ESMTPSA id 4ML17l1hvRz35vG7h
for [email protected]; Sun, 4 Sep 2022 14:54:43 +0900 (JST)
DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=sanzo.org;
[email protected]; q=dns/txt; s=dkim-ed25519; t=1662270880; h=date : from :
message-id : to : subject : content-type : mime-version :
content-transfer-encoding : from;
bh=47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=;
b=2ne23XnmFelQLySuMfq1zX7I1KQt3GAIx4TIKd5aicfPac8dfJmMEi4+wg1Sk2A8Le5om
DNTCIYzeIypNX8ICg==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sanzo.org;
[email protected]; q=dns/txt; s=dkim-rsa; t=1662270880; h=date : from :
message-id : to : subject : content-type : mime-version :
content-transfer-encoding : from;
bh=47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=;
b=qQRcdkksJwhJbJAypV9ZT8wRK0KKCoZ8AVu0VfSdG/L931iERNxozCUXF3UVnha35ws8x
+TlfnBCgCuwF4d32Gxr7f7yIHzXHpVZ5QK0WnZQ0gZ1MJ2IVnrxq4JIR+rMn1LyE2CGB2xD
MG9Z4gOVEB5N3qFt8/zB7UVejSZgOf7Vg9e1ztvxHRrqcfiTYhXnjePLaYrfr3LOQNB8P5O
6OUBgGwKQT9UehYAleTH587qZcaOGhYM0k1VLQCh6RtbPVC0ZXf2//PBAd6B7DCg4ACLN8Z
SpO7EhrRPjLJ4TkRVq3Fw6WjuKIvkxMCTJLd1chn3vdL5fn8+HhQO5SIdpVQ==
Received: from smi72700k.sanzo.org (miyazawa@ip6-localhost [127.0.0.1])
by smi72700k.sanzo.org (8.15.2/8.15.2/Debian-22) with ESMTPS id 2845sedi809535
(version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT)
for [email protected]; Sun, 4 Sep 2022 14:54:40 +0900
Received: (from miyazawa@localhost)
by smi72700k.sanzo.org (8.15.2/8.15.2/Submit) id 2845se43809534;
Sun, 4 Sep 2022 14:54:40 +0900
Date: Sun, 4 Sep 2022 14:54:40 +0900
From: Sanzo Miyazawa [email protected]
Message-Id: [email protected]
To: [email protected]
Subject:
Content-Type: text/plain; charset=UTF-8
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Virus-Scanned: clamav-milter 0.103.6 at smi72700k
X-Virus-Status: Clean
Hello
When i send code without attachment domain key is sign easily but when i try with attachment its getting me error
Unable to Domain Key sign the message
My code is
using (MailMessage mailMessage = new MailMessage())
{
mailMessage.From = new MailAddress("[email protected]", "Soni");
mailMessage.To.Add(new MailAddress("[email protected]"));
mailMessage.Subject = "Reminder : Subject";
mailMessage.SubjectEncoding = System.Text.Encoding.UTF8;
mailMessage.Body = "body";
mailMessage.BodyEncoding = System.Text.Encoding.UTF8;
mailMessage.IsBodyHtml = true;
mailMessage.Attachments.Add(new Attachment(@"C:\TempFolder\file.txt"));
try
{
var domainKeySigner = new DomainKeySigner(privateKey, Domain, "email", new string[] { "From", "To", "Subject", "Feedback-ID" });
var dkimSigner = new DkimSigner(privateKey, Domain, "email", new string[] { "From", "To", "Subject", "Feedback-ID" });
mailMessage.DomainKeySign(domainKeySigner);
mailMessage.DkimSign(dkimSigner);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
try
{
client.Send(mailMessage);
Console.WriteLine("Success");
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
mail will be send but dkim not been proper verfiyed . What's the issue. Please get me solution
Thanks
Naveen Soni
Hi there,
found this really promising project, after almost smashing my keyboard against the next wall, while searching for a way to DKIM-Sign emails in C#.
Compiling works perfectly (not a single warning/error), but when i try to execute even a simple program, like the example one from the readme, it gives me an exception when calling the DkimSign-method.
Here's, what it says:
Unhandled Exception:
System.TypeInitializationException: An exception was thrown by the type initializer for DKIM.MailMessageText ---> System.NullReferenceException: Object reference not set to an instance of an object
at DKIM.MailMessageText..cctor () [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at DKIM.MailMessageExtensions.DkimSign (System.Net.Mail.MailMessage message, DKIM.DkimSigner signer) [0x00000] in <filename unknown>:0
at Sendmail.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: An exception was thrown by the type initializer for DKIM.MailMessageText ---> System.NullReferenceException: Object reference not set to an instance of an object
at DKIM.MailMessageText..cctor () [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at DKIM.MailMessageExtensions.DkimSign (System.Net.Mail.MailMessage message, DKIM.DkimSigner signer) [0x00000] in <filename unknown>:0
at Program.Main (System.String[] args) [0x00000] in <filename unknown>:0
Any idea?
P.S.: Here's an example of where exactly the exception occurs:
using System.Net.Mail;
using DKIM;
static class Program{
public static void Main(string[] args){
MailMessage mail = new MailMessage();
mail.From = new MailAddress("[email protected]");
mail.To.Add(new MailAddress("[email protected]"));
mail.Subject="DKIM.Net Test";
mail.Body="Some stuff about stuff and such...";
IPrivateKeySigner pks = PrivateKeySigner.Create(@"-----BEGIN RSA PRIVATE KEY-----
<The private key goes here>
-----END RSA PRIVATE KEY-----
");
DkimSigner dkim = new DkimSigner(pks, "domain.org", "dkim", new string[] { "From", "To", "Subject" });
mail.DkimSign(dkim); //And here the exception goes off...
}
}
Hi
I sign System.Net.Mail.MailMessage using DKIM.Net . When subject and body are English text. Dkim is being passed but when subject or body is Farsi Dkim fails . I set encoding as below
MyMessage.SubjectEncoding = Encoding.UTF8; MyMessage.BodyEncoding = Encoding.UTF8;
but it doesn't work .
Any clue or hint to solve it
Thanks
I tried using this with a HTML email and sent it to Port25's verifier and received this:
Result: fail (signature doesn't verify)
Any ideas?
It would be great if you showed the DNS TXT entries that correspond to your sample. Minues the private key, of course. :)
MailMessageText
导出的带附件的邮件内容中文件名不会被编码(如中文等),问题在MailMessageText.Send3
方法调用第三参数allowUnicode
,这个参数应该传入false,不应该是true。
MailMessageText.GetText
内应该使用:
Send3(message, mailWriter, false, false);
带附件(Attachments
)或AlternateViews
的邮件不支持签名,在MailMessageExtensions.DkimSign
中直接拒绝了multipart
格式的邮件。问题在multipart
格式邮件每次生成邮件内容都会随机产生boundary
内容分隔符,根源在string System.Net.Mime.MimeMultiPart.GetNextBoundary()
方法,每次调用输出一个新的分隔符。
如果能够修改GetNextBoundary
使签名时和发送时产生的分隔符一致,那么就可以在MailMessageExtensions.DkimSign
中去掉那行限制。
很高兴,有办法修改GetNextBoundary
方法的调用,使他返回的内容完全自主可控,参考 https://github.com/bigbaldy1128/DotNetDetour 这个库,可以hook这个方法然后返回我们的一个值。
因为签名和发送是在不同时间内,时间有可能导致签名时是8:05,而发送时是8:06,从而导致带Date header的签名失败,但签名时建议携带Date header一起签名。
so 这个问题hook System.Net.Mail.Message.PrepareHeaders
可以解决,每次原始函数处理完成后我们获取System.Net.Mail.Message.Headers
,然后把Date header删掉,然后写入我们的值。
我参考的本仓库Email
和MailMessageText
写的一个签名类,根据上面发现的问题使用了相应的解决方案,可参考 https://github.com/xiangyuecn/DKIM-Smtp-csharp/blob/master/EMail_DKIM.cs
Add to a nuget package please.
Hi, I've seen your response to a previous question regarding alternate views.
Is there any component you are familiar with and can recommend, which does support DKIM signing of an email with an alternate view?
Regards,
Hi,
I'm trying to use DKIM.NET to sign email messages being sent through gmail and getting the following error back from [email protected] on the domain key signature:
----------------------------------------------------------
DomainKeys check details:
----------------------------------------------------------
Result: permerror (DK_STAT_SYNTAX: Message is not valid syntax. Signature could not be created/checked)
ID(s) verified: header.=
DNS record(s):
The generated header is:
DomainKey-Signature: a=rsa-sha256; c=simple; d=showcaselane.com; h=From:To:Subject; q=dns;
s=selector;
b=UjIbMn/14hGIJn/BzRYuIPqjueRm47jh16FNAfY3ZFQ3LugTXFe/Vc8knQFuNtqV9yMpc1OGBsyK8jAHJ/4C55oyeixzUkcmZwAtenpml30PJG421dm3jb8maivJFkW9i/qFQ9MiDzWazhIlAJN1rDhCV/0blkFyhizTExNS/Bs=;
Signing with DKIM (as opposed to DomainKeys) works fine.
Hello,
Was wondering if you've had any thoughts on how to address the issue with messages that have Alternate Views?
Brendan
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.