With the shut down of Less secure apps by Google on May 30, 2022, using Gmail with nodemailer now throws an error that says response: '535-5.7.8 Username and Password not accepted. Learn more at\n' + '535 5.7.8 https://support.google.com/mail/?p=BadCredentials. The Nodemailer docs appears to not be updated yet regarding this issue of Less secure apps but suggest to use another delivery provider. I used to just turn on LSA, store the credentials in an environment variable and let nodemailer do its thing, with this change, how can one still use gmail with nodemailer? There are no youtube tutorials to fix this yet and looking at the google documentation, it doesn't show nodemailer
Solved it by creating App password inside Google account. You must have 2-step verification actived.
Open Mail > Settings > See all Settings > Forwarding and POP/IMAP.
Enable POP download: & Enable IMAP access: (then save the settings). Mail Settings Image
Open Your Gmail Account > security > 2-step verification(enable it).
Go to App Passwords > select device > select app(you can create any custom app).
Copy App Password and use it in your application.
You should look into xoauth Nodemailer appears to support serval oauth options
let transporter = nodemailer.createTransport({
host: "smtp.gmail.com",
port: 465,
secure: true,
auth: {
type: "OAuth2",
user: "user#example.com",
clientId: "000000000000-xxx0.apps.googleusercontent.com",
clientSecret: "XxxxxXXxX0xxxxxxxx0XXxX0",
refreshToken: "1/XXxXxsss-xxxXXXXXxXxx0XXXxxXXx0x00xxx",
accessToken: "ya29.Xx_XX0xxxxx-xX0X0XxXXxXxXXXxX0x",
expires: 1484314697598,
},
});
Related
I am trying to set up email verification in my app using nodemailer with a Gmail account.
My problem is that it reports an error, stating that my Username and Password have not been accepted:
There was an error: Error: Invalid login: 535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8 https://support.google.com/mail/?p=BadCredentials a3sm2007362wri.89 - gsmtp
const transporter = nodemailer.createTransport({
host: "smtp.gmail.com",
service: "Gmail",
port: 465,
secure: true,
auth: {
user: process.env.USER,
pass: process.env.PASS,
},
});
transporter.sendMail(
{
from: process.env.USER,
to: email,
subject: subject,
text: text,
},
(error) => {
if (error) {
return console.log("There was an error: " + error);
}
console.log("Email sent successfully");
}
);
I can confirm that process.env.USER and process.env.PASS are correct, and that I have also allowed less secure apps.
Is there something I am missing/not understanding?
"From May 30, 2022, Google no longer supports the use of third-party apps or devices which ask you to sign in to your Google Account using only your username and password."
https://support.google.com/accounts/answer/6010255?hl=en
Solution
Go to your Google Account
Find Security Menu
Enable 2-Step Verification
After that you will see "App Password" option in Security page. (If not search it in Google Account Search box.
Select Mail from the "Select App" dropdown
Select the device from "Device" dropdown and click the "Generate" button.
Copy password and use it in your application where required.
Username and Password not accepted. normally means that you need to use an apps password instead of the users true password
Using OAuth 2.0 Mechanism should work as well but may be a little harder to implement.
Check if the user has 2fa enabled this is normally what causes it.
I faced exactly the same problem and google canceled the less secure apps and the solution is
from manage your account
select security
from Signing in to Google ==> make your account 2- step verification
from Signing in to Google ==> select app passwords
make a password for nodemailer and use it instead of your password
see this image
Nodemailer documentation for 2LO states you can make a config setup as such: Note I'm using a web unique address example.com which is email-hosted with gsuite:
host: 'smtp.gmail.com',
port: 465,
secure: true,
auth: {
auth: 'OAuth2',
user: 'mail#example.com',
serviceClient: emailKey.client_id,
privateKey: emailKey.private_key,
}
And you can make a gcp service account with the right config according to the most up-to-date tutorial I can find. However it gives this error:
Error: Missing credentials for "PLAIN" ... code: 'EAUTH', command: 'API'
There are no solved issues on this, here is one for reference.
All "Accepted answers" in related stack overflow questions I found are out of date since the JSON output from GCP service account no longer includes refresh and access tokens. This one
though looks like its gmail specific.
Any recommendations? Am I required to use an access token set up? Because I couldn't find good documentation on how to do this. Perhaps the relevant google documentation, because I can't distinguish which is for unique web addresses and which is #gmail.com-specific.
You typed in auth: 'OAuth2' instead of type: 'OAuth2'
I am working on deploying my Node.js app. However I am having issues with having the registration email getting sent out.
const transporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
user: GMAIL_USER,
pass: GMAIL_PASS,
},
});
......
......
transporter.sendMail({
to: newUser.email,
subject: 'Confirm Email',
html: `Please click this email to confirm your email: ${url}`
});
This works perfectly when I try running it on local host, but as soon as I upload the files to my server and try it, google blocks the sign in attempt, and I get an email saying
Someone just used your password to try to sign in to your account. Google blocked them, but you should check what happened.
Every time, I click the button "this was me", but any future attempts still get blocked.
I have "less secure apps" enabled. Is there a way to whitelist an IP to send from my gmail? or a way to get this working in general?
You have two options.Either you set the access to less secure apps setting to Enabled or you obtain an accessToken and a refreshToken from Google OAuth2.0 and use them in your nodemailer config
For option one go to https://www.google.com/settings/security/lesssecureapps
For option two go to https://console.developers.google.com/apis/credentials
if you choose option two your config for the transport will look something like this:
auth: {
type: 'OAuth2',
user: 'user#example.com',
accessToken: 'ya29.Xx_XX0xxxxx-xX0X0XxXXxXxXXXxX0x'
}
Sometimes people who don't assign recovery email, phone number .In that scenario also google hinders login. In my case google first allowed me on turning less secure app but very next day it denied. So I added recovery email for that particular email and it worked. So that's how I think google security algo works.
Had to fill out some hidden captcha for gmail, then everything worked fine. Sadly dont have the link, or id post it.
I am using nodemailer in order to send email to customers.
Here how I configured my transporter :
const mailTransport = nodemailer.createTransport({
service:'Gmail',
auth: {
user : "xxxx",
pass : "xxxx",
});
Unfortunately it doesn't work and I got "Invalid Login error". I checked on the web and autorized "less security connections" through settings account.
Unfortunately I stuck with the same error...
Could explain me how can I do that ?
Thanks
It is recommended to generate an app password for GMail, and use this with Nodemailer.
This will bypass any 2FA dialogs and any 'sign in authorizations' you may get when using your standard password.
See 'using Gmail' in the Nodemailer docs.
I use nodemailer to send email to my users, previously I used gmail and it work just fine, but now, Im my custom email which provided by gmail
admin#example.io
Heres the code
var transporter = nodemailer.createTransport(smtpTransport({
host : 'smtp.gmail.com',
secureConnection : true,
auth : {
user: 'admin#example.io',
pass: 'pass'
}
}));
Since my custom account is from gmail, I expect the host to be stmp.gmail.com, but it shows this error
{ [Error: Invalid login:]}
Im not sure what is the problem over here.
GoogleApps use the same smtp server.
Make sure your google apps administrator doesn't block SMTP relay service.
https://support.google.com/a/answer/2956491?hl=en