I am trying to setup nodemail, but run into a strange issue where I cannot wrap my head around. Whenever I fill in the credentials as a string, everything works fine (but of course I don't want this). If I start using env variables, then I get the following error message:
UnhandledPromiseRejectionWarning: Error: Missing credentials for "PLAIN"
It's using a gmail account to send an email. The account has the bypass for unsafe accounts enabled. When I add a console.log() statement, the password is clearly visible. Does anyone have any idea why this is happening and how this can be resolved. Below you'll find a code snippet which sends the email.
import nodemailer from 'nodemailer';
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: 'some-account@gmail.com',
pass: process.env.PWD,
},
});
export const sendUserCreateEmail = (to, firstName) => {
const mailOptions = {
from: 'someone',
to: to,
subject: 'It works',
html: `
<p>It works!</p>
`,
};
return transporter.sendMail(mailOptions);
};