Hi, folks. I’m putting a contact form on my developer profile that sends me an email on submission. Gmail doesn’t 100% play well with nodemailer, and I’m running into a problem where all the emails I’m receiving look like they’re coming from myself. According to the nodemailer docs:
“Gmail also always sets authenticated username as the From: email address. So if you authenticate as foo@example.com and set bar@example.com as the from: address, then Gmail reverts this and replaces the sender with the authenticated user.”
Unfortunately, I have no idea what this “authenticated username” business means. The long and short of it, I’m wondering if there’s anything I can do to actually get the “from” field submitted correctly, short of making a new email account through someone other than Gmail. The nodemailer chunk of code is as follows:
var transporter = nodemailer.createTransport({
service: "gmail",
auth: {
user: process.env.EMAIL,
pass: process.env.PASSWORD
}
});
app.post("/email", (req, res) => {
var mailOptions = {
from: `${req.body.name} <${req.body.email}>`,
to: process.env.EMAIL,
subject: req.body.subject,
text: req.body.text
};
transporter.sendMail(mailOptions, function(error, info) {
if (error) {
console.log(error);
res.send('Error');
} else {
console.log("Email sent: " + info.response);
res.send("Success");
}
});
});
Thanks in advance for any input!