I got error when i try to send mail with nodemailer and i'm using cpanel information

Viewed 40
    const nodemailer = require("nodemailer");

require("dotenv").config();

const smtpTransport = nodemailer.createTransport({
  host: "mail.ibendouma.com",
  port: 465,
  secure: true,

  auth: {
    user: process.env.USER,
    pass: process.env.SECRET,
  },
});


async function run() {
  let sendResult = await smtpTransport
    .sendMail({
      from: "'iBendouma' <service@ibendouma.com>",
      to: "tipox1254@gmail.com",
      subject: "Hello from iBendouma",
      text: "copier le code et verifier votre identité",
    })
    .then((res) => console.log(res))
    .catch((err) => console.log(err));

  console.log(sendResult);
}

run().catch((error) => console.log(error));

Error: Missing credentials for "PLAIN" at SMTPConnection._formatError (C:\Users\msypro\Desktop\test\node_modules\nodemailer\lib\smtp-connection\index.js:787:19) at SMTPConnection.login (C:\Users\msypro\Desktop\test\node_modules\nodemailer\lib\smtp-connection\index.js:441:38) at C:\Users\msypro\Desktop\test\node_modules\nodemailer\lib\smtp-transport\index.js:272:32 at SMTPConnection. (C:\Users\msypro\Desktop\test\node_modules\nodemailer\lib\smtp-connection\index.js:211:17) at Object.onceWrapper (events.js:519:28) at SMTPConnection.emit (events.js:400:28) at SMTPConnection._actionEHLO (C:\Users\msypro\Desktop\test\node_modules\nodemailer\lib\smtp-connection\index.js:1322:14) at SMTPConnection._processResponse (C:\Users\msypro\Desktop\test\node_modules\nodemailer\lib\smtp-connection\index.js:950:20) at SMTPConnection._onData (C:\Users\msypro\Desktop\test\node_modules\nodemailer\lib\smtp-connection\index.js:752:14) at TLSSocket.SMTPConnection._onSocketData (C:\Users\msypro\Desktop\test\node_modules\nodemailer\lib

msypro@Msypro MINGW64 ~/Desktop/test (master) $ node app.js Error: Missing credentials for "PLAIN" at SMTPConnection._formatError (C:\Users\msypro\Desktop\test\node_modules\nodemailer\lib\smtp-connection\index.js:787:19) at SMTPConnection.login (C:\Users\msypro\Desktop\test\node_modules\nodemailer\lib\smtp-connection\index.js:441:38) at C:\Users\msypro\Desktop\test\node_modules\nodemailer\lib\smtp-transport\index.js:272:32 at SMTPConnection. (C:\Users\msypro\Desktop\test\node_modules\nodemailer\lib\smtp-connection\index.js:211:17) at Object.onceWrapper (events.js:519:28) at SMTPConnection.emit (events.js:400:28) at SMTPConnection._actionEHLO (C:\Users\msypro\Desktop\test\node_modules\nodemailer\lib\smtp-connection\index.js:1322:14) at SMTPConnection._processResponse (C:\Users\msypro\Desktop\test\node_modules\nodemailer\lib\smtp-connection\index.js:950:20) at SMTPConnection._onData (C:\Users\msypro\Desktop\test\node_modules\nodemailer\lib\smtp-connection\index.js:752:14) at TLSSocket.SMTPConnection._onSocketData (C:\Users\msypro\Desktop\test\node_modules\nodemailer\lib\smtp-connection\index.js:191:44) { code: 'EAUTH', command: 'API' } undefined

1 Answers

This error Error: Missing credentials for "PLAIN" at SMTPConnection._formatError occurs when your credentials are missing. First thing you can do is to check whether the env file is specified properly in the code. You have to make sure that your index.js or server.js (or the name of your nodemailer code file) is in the same directory as env file.

If the above is all correct then try adding quotes around your env variable like below.

auth: {
    user: `${process.env.USER}`,
    pass: `${process.env.SECRET}`,
},

Your auth field have to look like this.

auth: {
    user: "someone@gmail.com",
    pass: "somesecretpass",
},

Hope this worked!

Related