i created a contact form with nodemailer and when I submit the form i get this error. I allready use App Password... I am really unsure what the problem is...
Here is the Code:
const smtpConfig = {
transport: {
host: 'smtp.gmail.com',
port: 465,
secure: true,
auth: {
user: process.env.EMAIL,
pass: process.env.APPPASS
},
},
};
let transporter = nodemailer.createTransport(smtpConfig);
// verify connection configuration
transporter.verify(function(error, success) {
if (error) {
console.log(error);
} else {
console.log("Server is ready to take our messages");
}
});
app.post("/send", (req, res) => {
let form = new multiparty.Form();
let data = {};
form.parse(req, function(err, fields) {
Object.keys(fields).forEach(function(property) {
data[property] = fields[property].toString();
});
console.log(data);
const mail = {
sender: `${data.name} <${data.email}>`,
to: process.env.EMAIL, // receiver email,
subject: data.subject,
text: `${data.name} <${data.email}> \n${data.message}`,
};
transporter.sendMail(mail, (err, data) => {
if (err) {
console.log(err);
res.status(500).send("Something went wrong.");
} else {
res.status(200).send("Email successfully sent to recipient!");
}
});
});
});
And the Error which I get is :
Error: connect ECONNREFUSED 127.0.0.1:587 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1159:16) { errno: -4078, code: 'ESOCKET', syscall: 'connect', address: '127.0.0.1', port: 587, command: 'CONN' }
I hope someone of u guys can help me out. Thanks ;)