0

im sending otp email verification code to my users from my custom domain email with nodemailer package. I set dkim signature and it was working 3 months ago and my email was falling to incomebox. But some how after 3 months, when i try exactly same code and exactly same thing, mail falls to junk box and when i check mail header i see this: smtp.mailfrom=<$_MYDOMAIN>.com; dkim=fail (no key for signature) my code is below:

let transporter = nodemailer.createTransport(
    {
      host: process.env.AUTH_EMAIL_HOST,
      port: process.env.AUTH_EMAIL_PORT,
      secure: true,
      dkim: {
        domainName: process.env.DKIM_DOMAIN,
        keySelector: process.env.DKIM_SELECTOR,
        privateKey: fs.readFileSync(process.env.DKIM_PRIVATE_KEY_FILE_PATH, "utf8"),
        cacheDir: '/tmp',
        cacheTreshold: 2048,
      },
      auth: {
        user: process.env.AUTH_EMAIL,
        pass: process.env.AUTH_PASS,
      }
    }
);

const otp = `${Math.floor(100000 + Math.random() * 900000)}`

//mail options
const mailOptions = {
    from: process.env.AUTH_EMAIL,
    to: email,
    subject: "Verify your email",
    html: `<p>Enter <b>${otp}</b> in the app to verify your email adress and complate the signup</p>
           <p>This code <b>expires in 1 hour</b></p>`,

};

and my nodemailer version is: "nodemailer": "^6.9.2", (just updated and also tried old versions, still it was not working)

(im sure dkim key and signature set on email hosting because it was working properly and i didn't change anything...) what do you guys think problem can be? thanks a lot in advance for your guidness

Kimse
  • 41
  • 1
  • 6

1 Answers1

0

The error states that a key to decrypt the message header was not found. This can indicate a temporary error in DNS lookups for your domain, or the record you published is no longer in the right place.

That could be caused by a change in the DKIM selector name, for example. The first place to look is in DNS at DKIM_SELECTOR._domainkey.DKIM_DOMAIN. There should be a TXT record there that starts with "v=DKIM1" and hold you public key.

See also https://serverfault.com/questions/909909/email-dkim-temperror-no-key-for-signature

Reinto
  • 885
  • 6
  • 9