I can send mail while in development but mails are not delivered after I deploy to vercel. I have checked that the environment variable there are correct. i am using node js for my backend and react js for my frontend and i am sending email with nodemailer. see my code below
const sendEmail = async({
to,
html,
subject
}) => {
const transporter = nodemailer.createTransport({
host: "smtp-mail.outlook.com",
port: 587,
secure: false,
auth: {
user: process.env.EMAIL_USER,
pass: process.env.EMAIL_PASS,
}
});
const mailOptions = {
from: process.env.EMAIL_USER,
to,
subject,
html
};
try {
await transporter.sendMail(mailOptions);
} catch (error) {
console.log(error);
}
};
I have checked the environment variables, which are correct. I get this error on vercel logs:
Error: Invalid login: 535 5.7.3 Authentication unsuccessful
[CH5PR03CA0008.namprd03.prod.outlook.com 2024-05-30T11:35:24.043Z
08DC808625FCE55E] at SMTPConnection._formatError
(/var/task/server/node_modules/nodemailer/lib/smtp-connection/index.js:798:19)
at SMTPConnection._actionAUTHComplete
(/var/task/server/node_modules/nodemailer/lib/smtp-connection/index.js:1577:34)
at SMTPConnection.
(/var/task/server/node_modules/nodemailer/lib/smtp-connection/index.js:1531:18)
at SMTPConnection._processResponse
(/var/task/server/node_modules/nodemailer/lib/smtp-connection/index.js:982:20)
at SMTPConnection._onData
(/var/task/server/node_modules/nodemailer/lib/smtp-connection/index.js:763:14)
at SMTPConnection._onSocketData
(/var/task/server/node_modules/nodemailer/lib/smtp-connection/index.js:195:44)
at TLSSocket.emit (node:events:517:28) at addChunk
(node:internal/streams/readable:368:12) at readableAddChunk
(node:internal/streams/readable:341:9) at Readable.push
(node:internal/streams/readable:278:10) { code: ‘EAUTH’, response:
‘535 5.7.3 Authentication unsuccessful
[CH5PR03CA0008.namprd03.prod.outlook.com 2024-05-30T11:35:24.043Z
08DC808625FCE55E]’, responseCode: 535, command: ‘AUTH LOGIN’ }
2
Answers
Try adding the properties below:
I have exactly the same error in deployed express.js backend on Vercel :
Based on the code below using promise to wrap nodemailer.sender as suggested in: Nodemailer in vercel not sending email in production
Any advice on this problem?