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

使用Nodemailer发送邮件时链接不可点击的问题求助

解决Nodemailer+Brevo发送邮件链接无法点击的问题

你的问题出在HTML字符串的手动转义处理上,尤其是引号的转义导致邮件客户端无法正确识别链接属性。直接按下面的方法修改代码即可解决:

修复方案1:用模板字符串写HTML(推荐)

别再手动转义<>和引号了,用ES6的模板字符串(反引号)直接写HTML内容,既能保证结构正确,又不容易出错:

var link = "http://google.com";
const mailOptions = {
    from: process.env.RESET_PASSWORD_EMAIL,
    to: email,
    subject: 'Password Reset',
    html: `
        <p>You are receiving this email because you have requested the reset of the password for your account.</p><br />
        <p>Please click on the following link, or paste this into your browser to complete the process:</p>
        <a href="${link}">Reset password</a><br />
        <p>If you did not request this, please ignore this email and your password will remain unchanged.</p>
    `
};

修复方案2:补充完整HTML结构

有些邮件服务商(比如Brevo)需要完整的HTML文档才能正确解析链接,加上<html>和<body>标签更稳妥:

var link = "http://google.com";
const mailOptions = {
    from: process.env.RESET_PASSWORD_EMAIL,
    to: email,
    subject: 'Password Reset',
    html: `
        <!DOCTYPE html>
        <html>
        <body>
            <p>You are receiving this email because you have requested the reset of the password for your account.</p><br />
            <p>Please click on the following link, or paste this into your browser to complete the process:</p>
            <a href="${link}" target="_blank">Reset password</a><br />
            <p>If you did not request this, please ignore this email and your password will remain unchanged.</p>
        </body>
        </html>
    `
};

问题根源

你原代码里用\&quot;转义引号,导致最终生成的HTML里href属性变成了href=&quot;http://google.com&quot;,而不是标准的href="http://google.com"。邮件客户端识别不了这种转义后的引号,自然就把链接当成普通文本,无法点击。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.24 06:52:34