I've installed the email package and tried to sent a test mail, but it presents me with the following error: AuthError: Invalid login - 535-5.7.8 Username and Password not accepted
I'm sure the credentials are correct and the code is the same as: https://github.com/ideaq/meteor-email
/server/init.js
process.env.MAIL_URL="smtp://USERNAME%40gmail.com:[email protected]:465/";
console.log(process.env.MAIL_URL);
Email.send({
from: "[email protected]",
to: "[email protected]",
subject: "Meteor Can Send Emails via Gmail",
text: "test"
});
also tried:
// configure email later for validation and sending messages
smtp = {
username: '[email protected]',
password: 'my-pw',
server: 'smtp.gmail.com',
port: 465
};
process.env.MAIL_URL = 'smtp://' + encodeURIComponent(smtp.username) + ':' + encodeURIComponent(smtp.password) + '@' + encodeURIComponent(smtp.server) + ':' + smtp.port;
I can't seem to find any other information around this problem or how to followup on it. Who can give me a clue?
thx for the suggestions guys! I fixed it by actually turning ON 2-step verification, generate an app password and use THAT as login. Strange solution, but it worked!
Solution: It's the gmail security for less secure apps. Also a quick solution will be to turn off the access Allow less secure apps
Solution: Best way will be to work with 2-Step verification 2-Step Verification
In case you're using OAuth2 and you're facing the issue above, configuring my transporter as shown below resolved the error for me.
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 not sure 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With