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

前端 未结 8 1930
广开言路
广开言路 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:36

    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

    0 讨论(0)
  • 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

    0 讨论(0)
  • 2021-01-31 18:41

    Google don't allow you to send direct e-mail to other's. First of all you have to create a app password .For that thing please follow below steps to get it done

    1. Go to your manage account section.
    2. Then click on the security link in left side.
    3. In the signing in to the google click on app password and it will ask you to sign in again after sign in
    4. It will ask "select app", for mail purpose "select mail" and after that select device from which you want to send mail.
    5. After all these steps, it will generate password for that thing and insert that like this
        var smtpTransport = nodemailer.createTransport({
        service: "Gmail",
        auth: {
            user: "example@example.com",
            pass: "password"
        }
    

    That's it.

    0 讨论(0)
  • 2021-01-31 18:42
    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 captcha option" (Allow access to your Google account). Here is the link : https://accounts.google.com/DisplayUnlockCaptcha

    0 讨论(0)
  • 2021-01-31 18:51
    let transporter = nodeMailer.createTransport({
        host: 'smtp.gmail.com',
        port: 587,
        secure: true,
        auth: {
            user: 'example@gmail.com',
            pass:'your gmail pass'
        }
    });
    
    0 讨论(0)
  • 2021-01-31 18:56

    For me secure:true was giving ssl errors. I changed secure:false as below and worked for me.

    let transporter = nodeMailer.createTransport({
        host: 'smtp.gmail.com',
        port: 587,
        secure: false,    //<<here
        auth: {
            user: 'example@gmail.com',
            pass:'your gmail pass'
        }
    });
    
    0 讨论(0)
提交回复
热议问题