E-mail getting rejected sent by Nodemailer

Viewed 485

enter image description hereI am trying to send an email which includes HTML content with the help of nodemailer-express-handlebars. Every time my mail gets blocked by the Gmail which can be checked in sender's Gmail sent-box whereas I got success msg from nodemailer Email sent: 250 2.0.0 OK 1595608108 i66sm6757247pfc.12 - gsmtp I am unable to understand why this happening as when I send a mail with text, it gets delivered.

NODEMAILER CODE

sendMail=(email)=>{
    var transporter = nodemailer.createTransport({
        service: 'gmail',
        auth: {
          user: 'emailId',
          pass: 'password'
        }
      });

      transporter.use('compile',hbs({
          viewEngine:{
            partialsDir:"./views/",
            defaultLayout: "",
            layoutsDir: "",
          },
          viewPath:"./views/",
          extName:'.hbs',
      }))
      var mailOptions = {
        from: '<xyz@gmail.com>',
        to: email,
        subject: 'Your order has been placed successfully.',
        template:'mail',
        context:{
            name:"XYZ",
            address:"133"
        }
 
      };
      
      transporter.sendMail(mailOptions, function(error, info){
        if (error) {
          console.log(error);
        } else {
          console.log('Email sent: ' + info.response);
        }
      });
}
1 Answers

It's recommended to use OAuth2 with NodeMailer and Gmail. Using the plain username and password might be what's causing you problems.

Related