Search code examples
javascriptnode.jstypescriptemailnodemailer

Nodemailer email sent but not received


I've loked arround the Internet for some solutions people propose, but any of them works for me fe: this one or this other one, even using the example code from Nodemailer website, I get on console

Message sent: <c2666ca9-9850-ffce-bcce-8fad0b8f41b8@example.com>
Preview URL: https://ethereal.email/message/Yxi21TBgBufqRAO3Yxi21mTcOrtHln6cAAAAAXYGM7S1KpoqqzcPthnCZbg

But email never arrives.

If it helps, using TypeScript the code I'm using is

"use strict";
const nodemailer = require("nodemailer");

async function main() {
  let testAccount = await nodemailer.createTestAccount();

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

  let info = await transporter.sendMail({
    from: '"Fred Foo 👻" <foo@example.com>',
    to: "bepaxeb636@esmoud.com",
    subject: "Hello ✔",
    text: "Hello world?",
    html: "<b>Hello world?</b>",
  });

  console.log("Message sent: %s", info.messageId);

  console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
}

main().catch(console.error);

I'm sending the email to a temporary mail account


Solution

  • For anyone being arround with this trouble, as said, the Ethereal service used for the testAccount is just a fake service, never delivers any email. Consider using other mail service if you expect the mails to arrive.

    Hope this helps someone.