C# DKIMKeySigner Can't open attachments
Asked Answered
G

1

9

I'm sending mails to users with attachments. Mails that aren't signed, get a .pdf file (around 64kb) and are working perfectly fine.

However, when I sign them for other users, the PDF file becomes around 64 B and can't be opened.

I'm not doing anything with the attachments while signing, however.. so this is very odd.

My code for signing:

 email = SpecificMethods.DKIMSign(email);

internal static MailMessage DKIMSign(MailMessage email)
    {
        var privateKey = PrivateKeySigner.Create(@"-----BEGIN RSA PRIVATE KEY-----
         -----END RSA PRIVATE KEY-----");

        var domainKeySigner = new DomainKeySigner(privateKey, "***.com", "**", new string[] { "mime-version", "date", "subject", "from", "to", "content-type" });
        email.DomainKeySign(domainKeySigner);

        var dkimSigner = new DkimSigner(privateKey, "***.com", "**", new string[] { "mime-version", "date", "subject", "from", "to", "content-type" });
        email.DkimSign(dkimSigner);

        return email;
    }

And eventually send it. Nothing special happening there.

Any reason why my attachment would 'break'??

Guildhall answered 27/1, 2017 at 12:6 Comment(1)
I would recommend using my MimeKit and MailKit libraries for signing messages with DKIM and sending them via SMTP.Pharyngology
S
2

I think that you shall change the library used to sign the messages or the class used to send the actual email. I tried a quick search for an alternate to System.Net.SmtpClient but found none.

You did not specify which DLL package you used, so a Google search teleported me to this project

Unfortunately, if you look at the Readme...


Known Issues

As System.Net.Mail.SmtpClient generates boundary identifiers randomly and as this code hacks the SmtpClient to retrieve the full email content before sending the code cannot be used when sending with SmtpClient and the MailMessage when the MailMessage has an alternative view or an attachment.


Scenarist answered 30/1, 2017 at 10:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.