我使用NodeMailer创建了以下功能,它似乎在没有问题的情况下发送电子邮件(收到控制台和电子邮件中的“消息发送”通知),除了没有发送任何电子邮件的附件! 尝试了一堆电子邮件地址
尝试了一堆电子邮件地址(gmail,谷歌应用程序,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();
});
};
这是nodemailer文档中的一个问题.使用“filePath”更改“路径”以定义路径并将“内容”更改为文本的“内容”.为我工作.
var mailOptions = {
...
attachments: [
{ // utf-8 string as an attachment
filename: 'text1.txt',
contents: 'hello world!'
},
{ // utf-8 string as an attachment
filename: 'text1.txt',
filePath: 'text.txt'
},
]
}
