digitalocean ubuntu server email not sent

1.1k views Asked by At

I'm using a digitalocean ubuntu server. I deployed a node app to send emails.

 var transporter = nodemailer.createTransport({
      service: 'gmail',
      host:'smtp.gmail.com',
      auth: {
        user: '[email protected]',
        pass:'EmailPassword'
      }
    });

    var mailOptions = {
      from: 'Express Delivery',
      to: req.body.name,
      subject: 'password reset',
        text: ``,
        html:'<h1>express delivery</h1><hr><p><h2>your verification code is : '+v_code+'</h2><h2>please enter this code to reset your account</h2></p>'
    };

    transporter.sendMail(mailOptions, function(error, info){
      if (error) {
        res.status(500);
          res.send({'data':'email sending fail','err':error});
      } else {
        console.log('Email sent: ' + info.response);
          res.status(200);
          res.send({'data':'sent verification code'});
        });
      }
    });

but i have an error.

{ "data": "email sending fail", "err": { "code": "EAUTH", "response": "534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbs\n534-5.7.14 EwlrhFraZdJas3vVEewnbhmhqPf5l2FEb63fMy3QW_TRXzv5f-xmbOtJ5eGJUf38kJvY3\n534-5.7.14 vHxXfNwHWjF0G4hNb9-L9Xp-jIWSmfAWRVz7utNbdFQ5mucKosCrvWz2v0571O2q>\n534-5.7.14 Please log in via your web browser and then try again.\n534-5.7.14 Learn more at\n534 5.7.14 https://support.google.com/mail/answer/78754 22sm9807004qkg.15 - gsmtp", "responseCode": 534, "command": "AUTH PLAIN" } }

This is the error. I want to know how to send email using smtp. and what is the error.

1

There are 1 answers

1
M. K. T. M. Sameera On

follow these things

  1. go to google's 2step-verification and set that up
  2. go and sign up for app password here
  3. then they ask to select an app and a device, (i chose custom for both), then press generate.
  4. the password they give, put that as email password