const transportConfigs = JSON.parse(fs.readFileSync(__dirname + '/mails/transport.json'));
const mailTransport = mail.createTransport(transportConfigs);
mailTransport.verify((error, success) => {
if (error) {
console.error(`Transport settings NOT verified - ${error}`);
verified = false;
return;
}
console.log('Transport settings verified');
verified = true;
});
function onFormSubmit(req, res) {
options = {
from: `"[STEELGRIM FORM] ${req.body.firstName} ${req.body.lastName}" <${transportConfigs.auth.user}>`,
to: transportConfigs.auth.user,
subject: `${req.body.subject} <${req.body.email}>`,
cc: "",
text: req.body.message
};
console.log(`Sending mail: ${options.from}`);
mailTransport.sendMail(options, (error, info) => {
if (error) {
res.status = 500;
res.send(error);
console.error(`Unable to send mail ${options.from}. ${error}`);
} else {
res.status = 200;
res.send(info.response);
console.log("Mail sent");
}
});