Username and Password not accepted when using nodemailer?

后端 未结 8 1740
悲哀的现实
悲哀的现实 2020-12-03 04:44

This is my settingController:

var sendSmtpMail = function (req,res) {
  var transport = nodemailer.createTransport({
  service:\'gmail\',
   auth: {
                 


        
8条回答
  •  忘掉有多难
    2020-12-03 04:59

    If you have enabled 2-factor authentication on your Google account you can't use your regular password to access Gmail programmatically. You need to generate an app-specific password and use that in place of your actual password.

    Steps:

    • Log in to your Google account
    • Go to My Account > Sign-in & Security > App Passwords
    • (Sign in again to confirm it's you)
    • Scroll down to Select App (in the Password & sign-in method box) and choose Other (custom name)
    • Give this app password a name, e.g. "nodemailer"
    • Choose Generate
    • Copy the long generated password and paste it into your Node.js script instead of your actual Gmail password. (You don't need the spaces.)

    Your script will now look like this:

    var transporter = nodemailer.createTransport({
      service: 'gmail',
      auth: {
        user: 'YOUR-GMAIL-USERNAME@gmail.com',
        pass: 'YOUR-GENERATED-APP-PASSWORD'
      }
    });
    

    I hope this helps someone.

提交回复
热议问题