DKIM signing not working with nodemailer using sendmail transport

I’m trying to sign my emails with DKIM but no luck. I tested with and it says it has a signature but is invalid. I am using the MEANjs setup and using nodemailer with the sendmail transport.

Here is the output

The DKIM signature of your message is:


Your public key is:

Key length: 2048bits

Your DKIM signature is not valid

My DO DNS records are:

MX 5 TXT @ “v=spf1 mx a ip4: -all” TXT gshncemail._domainkey “v=DKIM1;k=rsa;p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwPNXvkYZa/uzxabnVSuIYmS17cB7mnZOcEbRq2ojca621B6wApVXNjClbHHbt+ClKlkmcQEGI58eLC5BzftrZw8aLQTvoXUU3hmt3eTpM0ix7hADa39ORkHsSmwi38brY+T5S14cZUxJjKsRD6/HcM6SAhN+mSoQVmRjuNdWmIt5CzSdYaCvvbpKeRGWtVeL+5/ccKrYtHJYlRrNVnbNRc7Dzj2iygFekIqx9o/BBL/35IK0wzTvbnRty1sRJbDJLBxxMampm/Gh8Zo+mpN+xLWlgG9bMzTkeEDJFGgy+PNQx0/znHl4vFLwS8JnxBnG1Jtn1eDzILZ7OPOQmDuIlQIDAQAB”

My server side code the setup the mailer is:

var mailTransporter = nodemailer.createTransport(config.mailer.options);

mailTransporter.use('stream', nodemailerDkimSigner({
	domainName: '',
	keySelector: 'gshncemail',
	privateKey: fs.readFileSync('./config/dkimcerts/private.pem')

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hello there,

What you can try is to split the record into two parts using quotes and then run another test via or mxtoolbox.

An example will be:

“v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwPNXvkYZa/uzxabnVSuIYmS17cB7mnZOcEbRq2ojca621B6wApVXNjClbHHbt+ClKlkmcQEGI58eLC5BzftrZw8aLQTvoXUU3hmt3eTpM0ix7hADa39ORkHsSmwi38brY+T5S14cZUxJjKsRD6/” “HcM6SAhN+mSoQVmRjuNdWmIt5CzSdYaCvvbpKeRGWtVeL+5/ccKrYtHJYlRrNVnbNRc7Dzj2iygFekIqx9o/BBL/35IK0wzTvbnRty1sRJbDJLBxxMampm/Gh8Zo+mpN+xLWlgG9bMzTkeEDJFGgy+PNQx0/znHl4vFLwS8JnxBnG1Jtn1eDzILZ7OPOQmDuIlQIDAQAB”

Hope that this helps! Regards, Alex

The most common reason for this issue is if there is a problem with your private key or your DNS record. From a visual inspection the record itself looks ok. The first thing to check for is if in your key file there is an empty line after -----END CERTIFICATE----- at the end of the file and remove it if there is one:

3. /snipped code/
4. ... 20+ lines (its really not important how many if your cert is valid)
25. -----END CERTIFICATE-----