Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
131
rated 0 times [  135] [ 4]  / answers: 1 / hits: 16139  / 3 Years ago, sun, january 31, 2021, 12:00:00

I'm trying to use nodemailer(npm package) in my node app to send email through the contact page. It is giving me this 535 Authentication Failed error while I can assure you that my email and password are absolutely correct.


var express = require('express');
var router = express.Router();
const nodemailer = require("nodemailer");
require('dotenv').config();

router.route('/')
.post((req, res)=>{
const emailData=req.body;
let transporter = nodemailer.createTransport({
host: "smtp.zoho.in",
port: 465,
secure: true, // true for 465, false for other ports
auth: {
user: process.env.EMAIL_ID, // generated ethereal user
pass: process.env.EMAIL_PASS, // generated ethereal password
},
tls:{
rejectUnauthorized: false
}
});

let info = transporter.sendMail({
from: process.env.EMAIL_ID, // sender address
to: process.env.EMAIL_ID, // list of receivers
subject: "Quengenesis: Contact Message", // Subject line
text: `
From: ${emailData.fName} ${emailData.lName}
Email: ${emailData.email}
Phone: ${emailData.phone}
Message: ${emailData.message}`, // plain text body
// html: "<b>Hello world?</b>", // html body
});

// console.log("Message sent: %s", info.messageId);
// console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
// verify connection configuration
transporter.verify(function(err, success) {
if (err) {
res.send('There is a problem in the server, please try again later '+ err);
}
else {
res.send('Your message was sent successfully');
}
});

})

module.exports = router;


More From » node.js

 Answers
40

I enabled two-factor authentication in my Zoho account and then I created a separate app password from here under the security tab then used this password for the nodemailer. It worked.


[#50421] Thursday, January 14, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
miranda

Total Points: 655
Total Questions: 110
Total Answers: 121

Location: Netherlands
Member since Thu, Jul 1, 2021
3 Years ago
miranda questions
Sun, Jun 6, 21, 00:00, 3 Years ago
Tue, Mar 16, 21, 00:00, 3 Years ago
Sun, Feb 7, 21, 00:00, 3 Years ago
Mon, Jan 18, 21, 00:00, 3 Years ago
Fri, Jul 17, 20, 00:00, 4 Years ago
;