我无法使用 nodemailer 在邮件中发送 html 文本。
exports.send = function(req, res) {
console.log(req.query);
var mailOptions = {
to: req.query.email,
subject: req.query.sub,
text: 'Date of Interview: ' + req.query.dateOfInterview+ 'Time of Interview: ' + req.query.timeOfInterview + '' + req.query.assignedTechnicalPerson + '' + req.query.typeOfInterview + '' + req.query.interviewLocation
}
smtpTransport.sendMail(mailOptions, function(error, response) {
if (error) {
console.log(error);
res.end("error");
} else {
console.log("Message sent: " + response.message);
res.end("sent");
}
});
};
我收到的邮件是连续文本,没有任何行间距
我怎样才能使用其中的 html 标签发送相同的文本我也尝试过保留 html 但最终出现了很多错误
请告诉我正确的语法
任何帮助表示赞赏
这是 Nodemailer 最新版本的工作代码。
var smtpTransport = require('nodemailer-smtp-transport');
var transporter = nodeMailer.createTransport(
smtpTransport({
service: 'gmail',
auth: {
user: <Your gmail>,
pass: '*****'//ur password
}
})
);
transporter.sendMail({
from: '[email protected] /cdn-cgi/l/email-protection',
to: "[email protected] /cdn-cgi/l/email-protection",
subject: 'hello world!',
//text:"one"
html: '<html><body>Hello World....</body></html>'
}, function(error, response) {
if (error) {
console.log(error);
} else {
console.log('Message sent');
}
});
Note:要授予 smtp 访问权限,请执行以下操作:
- 对于 Gmail,您可能需要配置“允许安全性较低的应用程序”在你的
Gmail 帐户。点击这里 https://www.google.com/settings/security/lesssecureapps
- 您可能还需要解锁您的帐户“允许访问您的
谷歌帐户”使用 SMTP。
- 如果您在这种情况下使用 2FA,则必须创建一个应用程序特定密码。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)