你好,我在nodemailer中发送附件时使用下面的代码,邮件随附件一起发送,但是当我打开附件时,它什么也没显示
var mailer = require("nodemailer");
var smtpTransport = require('nodemailer-smtp-transport');
var transporter = mailer.createTransport(smtpTransport({
host: 'mailo2.abc.com',
}));
// send mail with defined transport object
var mail = {
from: '<john.doe@abc.com>', // sender address
to: "<john.doe@abc.com>'// list of receivers
subject: "Report for ABC Vital Business Function", // Subject line
html: "<b> ABC Vital Business Function Report Attached</b>", // html body
attachments: [{
filename: 'Report.html,
filepath:'.. /test-reports',
}]
}
transporter.sendMail(mail, function(error, response){
if(error){
console.log(error);
}else{
console.log("Message sent: " + response.message);
}
transporter.close();
});
答案 0 :(得分:0)
在附件对象中,其路径而不是文件路径。并确保您提供文件系统中的确切文件路径。
{
filename: 'Report.html',
path: '.. /test-reports/Report.html'
},