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

前端 未结 8 1937
广开言路
广开言路 2021-01-31 17:55

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;

            


        
8条回答
  •  遥遥无期
    2021-01-31 18:38

    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

提交回复
热议问题