You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Nodemailer提示邮件已发送但实际未收到的问题求助

Nodemailer Ethereal测试邮件未送达问题

我查阅了各类用户提出的解决方案,包括相关GitHub Issue,甚至直接使用Nodemailer官网的示例代码,执行后控制台输出如下:

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

但邮件始终未送达至我使用的临时邮箱。以下是我使用的TypeScript代码:

"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);

问题原因及解决办法

  1. Ethereal邮箱的本质特性
    Ethereal是Nodemailer提供的纯测试用SMTP服务,它不会将邮件真正投递到任何真实邮箱(包括临时邮箱)。控制台显示的"Message sent"仅表示邮件已成功提交到Ethereal服务器,实际邮件只会存储在Ethereal平台上,你只能通过控制台输出的Preview URL访问查看邮件内容。

  2. 如何真正发送邮件到真实邮箱
    如果需要将邮件实际送达收件箱,必须替换为真实的SMTP服务,比如:

  • 个人邮箱:Gmail、Outlook等(需提前开启SMTP服务并使用应用专用密码)
  • 第三方邮件服务:SendGrid、Mailgun、Postmark等(这类服务更适合生产环境,有完善的投递保障)

以下是改用Gmail SMTP的示例配置:

let transporter = nodemailer.createTransport({
  service: 'gmail',
  auth: {
    user: 'your-email@gmail.com',
    pass: 'your-app-password' // 注意:不是邮箱登录密码,是Google账号生成的应用专用密码
  }
});

内容的提问来源于stack exchange,提问作者Alberto Teixidó

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 02:25:16