Error: Invalid login: 535-5.7.8 Username and Password not accepted
Nahasean94 opened this issue · 1 comments
Nahasean94 commented
I have the following code
const sgMail = require('@sendgrid/mail')
async sendMail(emailInfo, log) {
sgMail.setApiKey(process.env.SENDGRID_API_KEY)
const msg = {
to: emailInfo.recipient,
from: process.env.EMAIL_SENDER,
html: emailInfo.body,
}
return sgMail.send(msg).catch((error) => {
console.error(error)
console.log(error.response.body)
})
}
in package json
"@sendgrid/mail": "^7.6.1",
The value for process.env.EMAIL_SENDER
I can confirm its verified on sendgrid dashboard.
Runnning the above code throws the following error:
2022-02-22T17:55:00.077Z | Error: Invalid login: 535-5.7.8 Username and Password not accepted. Learn more at
2022-02-22T17:55:00.077Z | 535 5.7.8 https://support.google.com/mail/?p=BadCredentials n19-20020a05600c4f9300b0037c06fe68casm3105077wmq.44 - gsmtp
2022-02-22T17:55:00.077Z | at SMTPConnection._formatError (/usr/src/app/node_modules/nodemailer/lib/smtp-connection/index.js:784:19)
2022-02-22T17:55:00.077Z | at SMTPConnection._actionAUTHComplete (/usr/src/app/node_modules/nodemailer/lib/smtp-connection/index.js:1536:34)
2022-02-22T17:55:00.078Z | at SMTPConnection.<anonymous> (/usr/src/app/node_modules/nodemailer/lib/smtp-connection/index.js:540:26)
2022-02-22T17:55:00.078Z | at SMTPConnection._processResponse (/usr/src/app/node_modules/nodemailer/lib/smtp-connection/index.js:947:20)
2022-02-22T17:55:00.078Z | at SMTPConnection._onData (/usr/src/app/node_modules/nodemailer/lib/smtp-connection/index.js:749:14)
2022-02-22T17:55:00.078Z | at TLSSocket.SMTPConnection._onSocketData (/usr/src/app/node_modules/nodemailer/lib/smtp-connection/index.js:189:44)
2022-02-22T17:55:00.078Z | at TLSSocket.emit (node:events:390:28)
2022-02-22T17:55:00.078Z | at addChunk (node:internal/streams/readable:315:12)
2022-02-22T17:55:00.078Z | at readableAddChunk (node:internal/streams/readable:289:9)
2022-02-22T17:55:00.078Z | at TLSSocket.Readable.push (node:internal/streams/readable:228:10) {
2022-02-22T17:55:00.078Z | code: 'EAUTH',
2022-02-22T17:55:00.078Z | response: '535-5.7.8 Username and Password not accepted. Learn more at\n' +
2022-02-22T17:55:00.078Z | '535 5.7.8 https://support.google.com/mail/?p=BadCredentials n19-20020a05600c4f9300b0037c06fe68casm3105077wmq.44 - gsmtp',
2022-02-22T17:55:00.078Z | responseCode: 535,
2022-02-22T17:55:00.078Z | command: 'AUTH PLAIN'
2022-02-22T17:55:00.078Z | }
What am i doing wrong?
Nahasean94 commented
My bad, I missed to add subject, and also had an issue with passing the api key via env variables.