Search code examples
javascriptnode.jsnodemailer

Nodemailer not sending email


I just set up my glitch project with a contact form and im trying to get it to send an email to me when someone fills out the form. The issue that I am having is that the server logs in console that the message has been sent with no errors but I never receive the email. You can find the code at https://glitch.com/edit/#!/gamesalt-dev?path=packages%2FPOSTroutes.js%3A2%3A39 and the contact form can be found at https://gamesalt-dev.glitch.me/.

let account = {
  user: "some.name@ethereal.email",
  pass: "************"
}
let transporter = nodemailer.createTransport({
  host: "smtp.ethereal.email",
  port: 587,
  secure: false,
  auth: {
    user: account.user,
    pass: account.pass,
  },
});

let mailOptions = {
  from: `"Contact" <${account.user}>`,
  to: "some.name@example.com",
  subject: "New Contact!",
  text: "Hello world",
  html: "<b>Hello world</b>",
}

let info = await transporter.sendMail(mailOptions, (error, info) => {
  if(error) return console.log(error);
  console.log("Message sent: %s", info.messageId);  
  console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
});

Solution

  • http://ethereal.email/

    Ethereal is a fake SMTP service, mostly aimed at Nodemailer users (but not limited to). It's a completely free anti-transactional email service where messages never get delivered.
    Instead, you can generate a vanity email account right from Nodemailer, send an email using that account just as you would with any other SMTP provider and finally preview the sent message here as no emails are actually delivered.

    Even if not, the server logs in console that the message has been sent with no errors the message you get is that the SMTP server successfully accepted your mail and added it to the send queue, but that will not guarantee that it will be delivered. The receiving SMTP server could still reject it and send a bounce message back.