I'm trying to send the email gmail smtp but I'm getting the error:
My email and password is correct I'm using the nodemailer for sending the mail;
var nodemailer = require('nodemailer');
// create reusable transporter object using SMTP transport
var transporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
admin: 'myuseremail.com',
pass: 'password'
}
});
var mailOptions = {
from: 'sender address', // sender address
to: to, // list of receivers
subject: 'Password Reset', // Subject line
html: 'Your one time password is : <b>' + temporaryPassword + ' </b>' // html body
};
transporter.sendMail(mailOptions, function (error, info) {
console.log(error,info);
}
in log i'm getting the error:
{
[Error: Invalid login]
code: 'EAUTH',
response: '535-5.7.8 Username and Password not accepted. Learn more at\n535 5.7.8 https://support.google.com/mail/answer/14257 k5sm20957041pdo.48 - gsmtp',
responseCode: 535
}
I try some link but that doesn't work:
https://laracasts.com/discuss/channels/general-discussion/help-email-doesnt-get-sent-with-gmail-smtp
var transporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
user: 'user@gmail.com',
pass: 'password'
}
});
Try the above and also, do the following which was worked for me.
login in to https://www.google.com/settings/security/lesssecureapps and TURN ON Access for less secure apps.
I hope it will work for you too.
Thank you.
First of all, you have to enable the settings to allow less secure apps for the gmail account that you are using. Here is the link : https://myaccount.google.com/lesssecureapps
Secondly, Allow access for "Display Unlock captch option" (Allow access to your Google account). Here is the link : https://accounts.google.com/DisplayUnlockCaptcha
In case you're using OAuth2 and you're facing the issue above, configuring my transporter as shown below resolved my issue.
const transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 465,
secure: true,
auth: {
type: 'OAuth2',
user: process.env.MAIL_USER,
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
refreshToken: process.env.GOOGLE_CLIENT_REFRESH_TOKEN
}
});
If you're unsure how to generate the id, secret and token, follow the steps here https://medium.com/@pandeysoni/nodemailer-service-in-node-js-using-smtp-and-xoauth2-7c638a39a37e
https://myaccount.google.com/lesssecureapps
Click on this link, On your Less secure app access. so after that gmail will send email to your device , confirm that it is you. You are done happy coding
var transporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
user: 'user@gmail.com',
pass: 'password'
}
});
Try this.
let transporter = nodeMailer.createTransport({
host: 'smtp.gmail.com',
port: 587,
secure: true,
auth: {
user: 'example@gmail.com',
pass:'your gmail pass'
}
});
来源:https://stackoverflow.com/questions/31516821/node-js-email-doesnt-get-sent-with-gmail-smtp