node.js email doesn't get sent with gmail smtp

半腔热情 提交于 2019-11-30 04:52:38
pavani sri
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.

  1. 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

  2. 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

Aravinth
var transporter = nodemailer.createTransport({
  service: 'Gmail',
  auth: {
    user: 'user@gmail.com',
    pass: 'password'
  }
});

Try this.

gowtham
let transporter = nodeMailer.createTransport({
    host: 'smtp.gmail.com',
    port: 587,
    secure: true,
    auth: {
        user: 'example@gmail.com',
        pass:'your gmail pass'
    }
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!