我使用 NodeMailer 创建了以下功能,它似乎可以毫无问题地发送电子邮件(控制台中的“已发送消息”通知和收到的电子邮件),但没有发送任何电子邮件的附件!
用一堆电子邮件地址(gmail、google 应用程序、hotmail)尝试过,但都在做同样的事情。请帮忙!
var sendWithAttachment = function(userMail, subject, html, attachment_path, cb){
var smtpTransport = nodemailer.createTransport("SMTP",{
service: "Gmail",
auth: {
user: "labs@domain.com",
pass: "password"
}
});
var mailOptions = {
from: "Labs <labs@domain.com>",
to: userMail,
subject: subject || "[blank]"
html: html || "[none]"
generateTextFromHTML: true,
attachments: [
{ // filename and content type is derived from path
path: attachment_path
},
{ // utf-8 string as an attachment
filename: 'check.txt',
content: 'checking that some attachments work...'
},
],
};
smtpTransport.sendMail(mailOptions, function(error, response){
if(error){
console.log(error);
cb(error, null);
}else{
console.log("Message sent: " + response.message);
cb(null, response);
}
smtpTransport.close();
});
};