I have been searching a lot for an answer, but I did not find my mistake yet. So maybe you can help me with this error I get when trying to send a mail from an unknown mail via nodemailer to my personal mail (for a contact form on my website):
api/mail.js
import nodemailer from 'nodemailer';
import {valueMissing} from "../../utils/functions";
export default function sendMail (req,res){
if (valueMissing(req.body.name) || valueMissing(req.body.subject) ||
valueMissing(req.body.message) || valueMissing(req.body.mail))
return res.status(202).json({ success: false });
else {
const transporter = nodemailer.createTransport({
port: 465,
host: 'smtp.xxx.xxx',
auth: {
user: process.env.MAIL_USER,
pass: process.env.MAIL_PW
},
});
const message = {
from: {
name: req.body.name,
address: req.body.mail
},
to: process.env.MAIL_USER,
subject: req.body.subject,
text: req.body.message
};
transporter.sendMail(message,error => {
if(error) {
console.log(error);
return res.status(202).json({
success: false
});
} else return res.status(200).json({
success: true
});
})
}
}
I have worked with nodemailer before, but back then I was sending mails from my mail to another person, not the other way around. In my research I found this tutorial - Creating A Contact Form With JavaScript / Nodemailer. What am I doing different? Seems like it should be working either way...
Thanks in advance :)