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

NextJS中Nodemailer动态收件人地址格式异常的解决求助

解决方案

这个问题是Nodemailer默认会将邮箱域名转换为Punycode编码(即xn--开头的格式),若你的邮件服务器不支持解析该编码,就会触发拒收错误。可以通过以下两种方式解决:

方法1:全局禁用Punycode转换

在创建Transporter时添加disablePunycode: true配置,强制Nodemailer使用原始域名格式:

const Transporter = await nodemailer.createTransport({
  host: "my-email-host.de",
  port: 25,
  secure: false,
  debug: true,
  logger: true,
  tls: {
    rejectUnAuthorized: false,
  },
  ignoreTLS: true,
  disablePunycode: true // 新增该配置项
});

方法2:单独处理收件人邮箱

如果不想全局禁用Punycode转换,可直接使用前端传来的原始邮箱字符串(需确保前端传入的格式正确),也可以添加简单的格式清理:

const Email = await Transporter.sendMail({
  from: "<IT-organization@example.de>",
  to: Recipient.trim(), // 清理前后空格
  subject: "Employment process",
  html: "Test Email"
});

额外提示

  • 先确认你的邮件服务器确实不支持Punycode编码,现代主流邮件服务器基本都兼容,但部分老旧或企业内部服务器可能存在限制。
  • 检查前端传来的邮箱是否包含全角字符或其他隐藏特殊字符,必要时在前端/后端添加邮箱格式校验逻辑。

内容的提问来源于stack exchange,提问作者MarcellusCodes

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.18 10:05:23