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.
Related
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,
},
});
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
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 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
I have a problem with nodemailer where the user receive the email with sent from my google account which used to authenticate gmail instead of the alias used in mail options.
Below is my code:
var smtpTransport = nodemailer.createTransport({
service: config.mailer.options.service,
auth: {
user: "xxxx#gmail.com",
pass: "password"
}
});
var mailOptions = {
to: user.email,
from: 'Test Email <aaa#aaa.com>',
subject: subject,
html: emailHTML
};
smtpTransport.sendMail(mailOptions);
Now when the user receive an email the email mentions that
from: Test Email xxxx#gmail.com
Instead of showing
from: Test Email aaa#aaa.com
Any help please
you also need to configure the alias in your gmail account. I faced the same issue but after configuring alias in gmail it worked.
check this link to configure https://support.google.com/mail/answer/22370?hl=en
Now, with Gmail, you can use aliases as your main account. Just go into Gmail settings under account and select default.