I'm trying to use gmail smtp with the latest version of nodemailer. I've done the steps that are described here. When sending a mail I still get the following errormessage:
Error: Invalid login: 535-5.7.8 Username and Password not accepted
It's pretty weird since I never try logging in with a password/username, but I use OAuth2 instead:
transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
type: 'OAuth2',
user: 'hello@company.com',
clientId: '<clientId>.apps.googleusercontent.com',
clientSecret: '<clientSecret>',
accessToken: '<accessToken>',
refreshToken: '<refreshToken>',
}
});
transporter.sendMail({
from: from,
to: to,
subject: subject,
text: message,
html: htmlMessage
}, function (err, data) {
if (err) {
console.log(err);
console.log("======");
console.log(subject);
console.log(message);
} else {
console.log('Email sent:');
console.log(data);
}
});
Does anyone know what I've missed? I tried doing all these steps to generate these tokens 3 times so I'm pretty sure all credentials are filled in correctly.
Thanks in advance