Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception on DKIM.MailMessageExtensions.DkimSign #8

Open
isendrak opened this issue Mar 30, 2015 · 1 comment
Open

Exception on DKIM.MailMessageExtensions.DkimSign #8

isendrak opened this issue Mar 30, 2015 · 1 comment

Comments

@isendrak
Copy link

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("sender@domain.org");
        mail.To.Add(new MailAddress("receiver@another-domain.com"));
        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...
    }
}
@jstedfast
Copy link

It looks like the MailMessageText static constructor is failing due to a null reference somewhere.

My guess is that since MailMessageText relies heavily on reflecting various non-public types from the BCL, that this is the problem.

I've just added support for DKIM signatures to MimeKit that you can use instead which does not rely on any non-public BCL classes because I've implemented my own MIME parser and serializer.

Since you'll probably need to send the message via SMTP, you'll probably also want to take a look at MailKit.

Hopefully Damien doesn't mind me making this suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants