palo
palo

Reputation: 169

How to send a result of query in email using nodemailer in node.js

I am making password recovery system in which i am getting password from database when email matches by the email entered by user. I want to send password in the mail but i am getting an error of [ERR_INVALID_ARG_TYPE].

I am getting result from database but mail is not sending because of that arg error.

How i can send that password in mail and how to correct that error?

app.post('/mail', (request, response) => {
  var e = request.body.e;
  console.log(e);
    var password = request.body.pwd;

    
    var sql = ` SELECT Employer_Password 
        FROM fyp_employers 
        WHERE Email_Address = ?`;
   var pass= connection.query(sql, [e], function (error, results, fields) {
      if(error){
        console.log(error);
      }
      else{

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

var mailOptions = {
  from: '[email protected]',
  to: request.body.e ,
  subject: 'Okay' ,
  text: results,
};
}

transporter.sendMail(mailOptions, function(error, info){
  if (error) {
    console.log(error);
  } else {
    console.log('Email sent: ' + info.response);
  }
});
});

})
app.listen(3000);

enter image description here

Upvotes: 0

Views: 624

Answers (1)

Abhinav Singh
Abhinav Singh

Reputation: 312

Your body should be a string or you can send html file, because mails are just text, One thing you can do is to loop through the array and make a string from the elements of the array.

let text='';

array.forEach(ele=>{
  text=text+String(ele)+' ';
})

Upvotes: 1

Related Questions