Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

259
Views
Nodemailer Error/Google oAuth2 APi error - playground: No refresh token or refresh handler callback is set
const nodeMailer = require("nodemailer");
const { google } = require('googleapis');



const oAuth2Client = new google.auth.OAuth2(
    process.env.CLIENT_ID,
    process.env.CLEINT_SECRET,
    process.env.REDIRECT_URI
  );
  
oAuth2Client.setCredentials({ refresh_token: process.env.REFRESH_TOKEN });

const sendEmail = async (options) => {
  const accessToken = await oAuth2Client.getAccessToken();
  const transporter = nodeMailer.createTransport({
    host: process.env.SMTP_HOST,
    port: process.env.SMTP_PORT,
    secure: true,
    service: process.env.SMTP_SERVICE,
    auth: {
      type: 'OAuth2',
      user: process.env.SMTP_MAIL,
      clientId: process.env.CLIENT_ID,
      clientSecret: process.env.CLEINT_SECRET,
      refreshToken: process.env.REFRESH_TOKEN,
      accessToken: accessToken,
    },
  });

  const mailOptions = {
    from: process.env.SMPT_MAIL,
    to: options.email,
    subject: options.subject,
    text: options.message,
  };

  await transporter.sendMail(mailOptions,function(err,info){
      if(err){
          console.log(err)
      } else {
          console.log('success')
      }
  });
};

module.exports = sendEmail;

when it says no refresh token , but each time when new req is made oAuth2Client creates new token and that is being passed into setting the credentials for refresh token, but ultimately the transporter is unable to process the mailing part.

In https://developers.google.com/oauthplayground : i've set API as "https://mail.google.com" and "Use your own OAuth credentials"

also the temp gmail account which i created for mailing purpose i activated Less secure app access to "On" mode.

can anyone help me to pass this error? reg

about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!