0

(node:1964005) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)

(node:1964005) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

exports.sendEmail = async (req, res) => {
    const outputMessage = `
<h1>Mail Details</h1>
<ul>
<li>Name: ${req.body.name} </li>
<li>Email: ${req.body.email} </li>
<li>Phone: ${req.body.phone} </li>
</ul>
<h1>Message</h1>
<p>${req.body.message}</p>
`

  let transporter = nodemailer.createTransport({
        host: "smtp.gmail.com",
        port: 465,
        secure: true,
        auth: {
            user: "", // gmail account
            pass: "", // gmail password
        }
    });

  // send mail with defined transport object
  let info = await transporter.sendMail({
        from: ' "info" <...@gmail.com>', // sender address
        to: ".....@windowslive.com", // list of receivers
        subject: "info✔", // Subject line
        html: outputMessage, // html body
  });

    
  res.status(200).redirect('/');

};
mc-user
  • 1,769
  • 4
  • 14
  • 25
  • Well, something within your `sendEmail` function is throwing an exception. But you don't have any exception handling. And that's what the error is telling you. Add some exception handling and check what exact exception is thrown. Then you can go on trying to prevent that exception – derpirscher May 30 '22 at 21:38
  • I did what you said. "ReferenceError: transporter is not defined" gave an error. How can I find a solution? – Utku Coşkun May 31 '22 at 15:02
  • Hm, that's strange. Are you sure you don't have a typo somewhere? Is that above the **exact** code you are using? Because I don't see how that error can result from that code ... – derpirscher May 31 '22 at 22:09

0 Answers0