Missing credentials for “PLAIN” nodemailer

后端 未结 6 1690
清歌不尽
清歌不尽 2020-12-03 10:47

I\'m trying to use nodemailer in my contact form to receive feedback and send them directly to an email. This is the form below.

6条回答
  •  一整个雨季
    2020-12-03 11:33

    Gmail / Google app email service requires OAuth2 for authentication. PLAIN text password will require disabling security features manually on the google account.

    To use OAuth2 in Nodemailer, refer: https://nodemailer.com/smtp/oauth2/

    Sample code:

    var email_smtp = nodemailer.createTransport({      
      host: "smtp.gmail.com",
      auth: {
        type: "OAuth2",
        user: "youremail@gmail.com",
        clientId: "CLIENT_ID_HERE",
        clientSecret: "CLIENT_SECRET_HERE",
        refreshToken: "REFRESH_TOKEN_HERE"                              
      }
    });
    

    And if you still want to use just plain text password, disable secure login on your google account and use as follows:

    var email_smtp = nodemailer.createTransport({      
      host: "smtp.gmail.com",
      auth: {
        type: "login", // default
        user: "youremail@gmail.com",
        pass: "PASSWORD_HERE"
      }
    });
    

提交回复
热议问题