'Node.JS: Nodemailer not sending emails even though there's no error

I'm trying to send an email using Node.JS and Nodemailer but it doesn't seem to send an email, even though there are no errors. I just don't receive anything.

I'm pretty sure I filled in all the email info correctly, I tried both port 25 and 465. There are no errors when you submit the contact form. I also port forwarded both ports (not sure if necessary).

I recreated my app in the codesandbox below:

https://codesandbox.io/s/unruffled-moon-d4sm0?file=/index.js

All the data is valid, feel free to play with it. Nodemailer is still new to me, hopefully someone can tell me where I went wrong.



Solution 1:[1]

Fixed! All I had to do was add smtpTransport as a parameter in createTransport and add the name variable.

Old

let transporter = nodemailer.createTransport({
    host: "mail.sj9.co",
    port: 465,
    secure: true, // true for 465, false for other ports
    auth: {
      user: "[email protected]", // generated ethereal user
      pass: "jailbreak", // generated ethereal password
    },
    tls: {
      rejectUnauthorized: false,
    },
  });

New

let transporter = nodemailer.createTransport(smtpTransport({
    name: "sj9",
    host: "mail.sj9.co",
    port: 465,
    secure: true, // true for 465, false for other ports
    auth: {
      user: "[email protected]", // generated ethereal user
      pass: "jailbreak", // generated ethereal password
    },
    tls: {
      rejectUnauthorized: false,
    },
  }));

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 SJ19