I am developing a website in nextjs, and when i send emails using nodemailer in my windows environment it works well both on development and production. But when i deploy the application on my ubuntu web server i am getting this error:
Error: Invalid login: 535 Authentication Failed
at SMTPConnection._formatError (webpack-internal:///(rsc)/./node_modules/nodemailer/lib/smtp-connection/index.js:616:19)
at SMTPConnection._actionAUTHComplete (webpack-internal:///(rsc)/./node_modules/nodemailer/lib/smtp-connection/index.js:1230:34)
at SMTPConnection.eval (webpack-internal:///(rsc)/./node_modules/nodemailer/lib/smtp-connection/index.js:432:26)
at SMTPConnection._processResponse (webpack-internal:///(rsc)/./node_modules/nodemailer/lib/smtp-connection/index.js:757:20)
at SMTPConnection._onData (webpack-internal:///(rsc)/./node_modules/nodemailer/lib/smtp-connection/index.js:589:14)
at SMTPConnection._onSocketData (webpack-internal:///(rsc)/./node_modules/nodemailer/lib/smtp-connection/index.js:144:48)
at TLSSocket.emit (node:events:519:28)
at addChunk (node:internal/streams/readable:559:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
at Readable.push (node:internal/streams/readable:390:5)
at TLSWrap.onStreamRead (node:internal/stream_base_commons:191:23)
at TLSWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
code: 'EAUTH',
response: '535 Authentication Failed',
responseCode: 535,
command: 'AUTH PLAIN'
}
here is my nodemailer configurations:
const transporter = nodeMailer.createTransport({
host: 'smtp.zoho.com',
port: 465,
secure: true, // use SSL
auth:{
user: process.env.USER,
pass: process.env.PASS
},
})
the emails are zoho based emails, [email protected], i have made communication to both my vps providers and zoho support but the error is not coming from their end.
Also i tried with gmail also, and the error is the same, and i have created app based password, and all the credentials are correct.
Anyone who can offer assistance, i will appreciate.
2
Answers
The issue was that
process.env.USER
was passing "root" instead of my email (username), after i changed process.env.USER to something likeprocess.env.EMAIL_USER
, my application was able to send the emails.As mentioned in the documentation, ensure following things are correct on our side:
smtppro.zoho.com
smtp domain.secure: true
means, it uses TLS. Read moreprocess.env.USER
andprocess.env.PASS
envrionment variables are set correctly in the machine.