NodeJS - Send free emails using Nodemailer and Gmail
Why Stack Overflow recommends it
Stack Overflow users link it when answering Nodemailer and Gmail authentication errors, mainly as a walkthrough for getting the OAuth2 client ID, secret and refresh token set up.
Recommended by 3 people across 3 different months, 2018 to 2020.
What it is
A short screencast showing how to send email from a Node.js app using the Nodemailer library and a Gmail account, with OAuth2 credentials created through Google's OAuth playground. The presenter walks through the setup and shares example code on JSFiddle.
What people said
Recommends thegreathypocrite · 2018-07 · Stack Overflow · on “Missing credentials for "PLAIN" nodemailer”
I was able to solve this problem by using number 3, Set up 3LO authentication, example from the nodemailer documentation (link: [LINK] ). My code looks like this: 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' } }); If you looked at the example in the link that I stated above, you can see there that there is a 'expires' property but in my code i didn't include it and it still works fine. T
Recommends Nicholas Gonzalez · 2020-03 · Stack Overflow · on “Google oauth 2.0 API password change Username and Password not accepted”
Similar to the answer above. This is how I structured mine and it worked right away. const transporter = nodemailer.createTransport({ host: "smtp.gmail.com", port: 465, secure: true, // true for 465, false for other ports auth: { type: "OAuth2", user: process.env.EMAIL, // email you are using with nodemailer pass: process.env.PASSWORD, // email password clientId: process.env.CLIENTID, clientSecrect:process.env.CLIENTSECRET, refreshToken: process.env.REFRESHTOK, accessToken: process.env.ACCESSTOK, }, tls:{ rejectUnauthorized:false } }); This link for the credentials worked as well. [this video] You have to navigate around as google web layout is a little different. For sure works though!
Recommends Luka Mlaker V. · 2020-09 · Stack Overflow · on “Missing credentials for "PLAIN" nodemailer”
We don't need to lower our Google Account Security for this. This works for me on localhost and live server. Versions: node 12.18.4 , nodemailer ^6.4.11 . STEP 1: Follow setting up your Google Api Access in this video AND IGNORE his code (it didn't work for me): [this video] STEP 2: Try this code in your main app file after you install nodemailer and dotenv via npm i nodemailer dotenv : require('dotenv').config(); //import and config dotenv to use .env file for secrets const nodemailer = require('nodemailer'); function sendMessage() { try { // mail options const mailOptions = { from: "MySite@mysite.com", to: "my_gmail@gmail.com", subject: "Hey there!", text: "Whoa! It freakin works now." }; // he
Cites JojoHalastra · 2020-01 · Stack Overflow · on “Can't send mails with nodemailer, using my gmail account - NodeJS”
I'm trying to send mails through my web application using NodeMailer and Gmail. I got everything needed - clientId, clientSecret, refreshToken and accessToken - followed this [this video] tutorial. Once I try to execute the code I get this message: Error: Mail command failed: 530-5.7.0 Authentication Required. Learn more at 530 5.7.0 [LINK] f12sm13931996wmf.28 - gsmtp at SMTPConnection._formatError code: 'EENVELOPE', response: '530-5.7.0 Authentication Required. Learn more at\n' + '530 5.7.0 [LINK] f12sm13931996wmf.28 - gsmtp', responseCode: 530, command: 'MAIL FROM' Tried googling it and nothing solved my prolem.