I writed this code in node.js - visual studio code, the database is mongoDB atlas (the code sends mail with token details after login):
function sendMail(email, name, tkn) {
let transporter = nodemailer.createTransport({
service: 'workers',
auth: {
user: process.env.EMAIL_ADDRESS,
pass: process.env.EMAIL_PASSWORD
}
});
let mailOptions = {
from: process.env.MAIL,
to: email,
subject: `welcome ${name}`,
text: `your token is ${tkn} `
};
transporter.sendMail(mailOptions, function (err, info) {
if (err) {
console.log(err);
} else {
console.log('email sent:' + info.response);
}
});
}
const checkPermission = async (req, res) => {
try {
/*let employed = */await Employed.findOne({
email: req.body.email,
password: req.body.password
}).then((employed) => {
const token = jwt.sign({ id: employed._id }, process.env.ACCESS_TOKEN_SECRET)
sendMail(employed.email, employed.full_name, token);
res.status(200).send(`successfull login ${employed}`)
})
} catch (err) {
res.status(400).send(`error: ${err.message}`);
}
}
this is the postman:
localhost:4000/checkPermission
it runs but the mail is not sended and i get this error in the terminal:
Error: connect ECONNREFUSED 127.0.0.1:587
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16) {
errno: -4078,
code: 'ESOCKET',
syscall: 'connect',
address: '127.0.0.1',
port: 587,
command: 'CONN'
}
do you know what the problem is? thanks ahead!