dmcgiv / DKIM.Net

DomainKeys Identified Mail (DKIM) and DomainKey email signing for .Net (C#)
31 stars 9 forks source link

Add Mail message attachment is getting Domain Key sign Exception #11

Open vesnaveen opened 6 years ago

vesnaveen commented 6 years ago

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("mailMessage.From@gmail.com", "Soni");
                mailMessage.To.Add(new MailAddress("To@gmail.com"));                          
                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

jstedfast commented 5 years ago

For anyone having this issue, I would recommend using MimeKit's DKIM support instead.

If you also need SMTP functionality to send the resulting message, you can use MimeKit with MailKit (since you won't be able to use MimeKit with System.Net.Mail.SmtpClient).

Hopefully Damien doesn't mind me making this suggestion since it appears that he is no longer maintaining this library.