nodemailer - 锚标签不起作用

时间:2015-12-09 21:54:35

标签: javascript node.js email gmail nodemailer

每当我尝试使用nodemailer v1.10发送带有锚标记的电子邮件时,我的电子邮件中就会混淆3D个字符。我相信这是%3D,在解码时代表=。我使用gmail作为SMTP传输的服务。

这是我在nodemailer中使用的“html”值

var resetUrl = req.protocol + '://' + req.get('host') + ':' + req.app.get('port') + '/password/reset?token=' + encodeURIComponent(digest);
options.html = 'To reset your password, click this <a href="' + resetUrl + '"><span>link</span></a>.<br>This is a <b>test</b> email.'

以下是我从收到的电子邮件中点击“显示原始内容”时的样子。

To reset your password, click this <a href=3D"http://192.168.1.=
109:3000:3000/password/reset?token=3DoU5J1vm4VTLl0Ru8SMI7x3YvF3Y%3D"><span>=
link</span></a>.<br>This is a <b>test</b> email.

我还注意到每行末尾都有=。这对gmail来说是正常的吗?我收到的电子邮件在gmail中看起来很正常。该链接具有蓝色字体颜色,并加下划线,但单击它时不起作用。我也在雅虎邮箱中尝试过,链接也不起作用。

2 个答案:

答案 0 :(得分:0)

我通过更改锚标记中使用的"'的引号来修复它

在:

options.html = 'To reset your password, click this <a href="' + resetUrl + '"><span>link</span></a>.<br>This is a <b>test</b> email.'

后:

options.html = "To reset your password, click this <a href='" + resetUrl + "'><span>link</span></a>.<br>This is a <b>test</b> email."

答案 1 :(得分:-2)

尝试使用htmlToText plugin编译HTML:

var nodemailer = require('nodemailer');
var htmlToText = require('nodemailer-html-to-text').htmlToText;
var transporter = nodemailer.createTransport();
transporter.use('compile', htmlToText());
transporter.sendMail({
    from: 'me@example.com',
    to: 'receiver@example.com',
    html: '<b>Hello world!</b>'
});
相关问题