我使用NodeMailer創建了以下函數,它似乎在沒有問題的情況下發送電子郵件(控制檯和收到的電子郵件中的「發送消息」通知),但沒有發送任何電子郵件的附件!NodeMailer附件不使用smtp/gmail發送
試了一堆電子郵件地址(Gmail,谷歌應用程序,Hotmail的),但都做同樣的事情。請幫忙!
var sendWithAttachment = function(userMail, subject, html, attachment_path, cb){
var smtpTransport = nodemailer.createTransport("SMTP",{
service: "Gmail",
auth: {
user: "[email protected]",
pass: "password"
}
});
var mailOptions = {
from: "Labs <[email protected]>",
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();
});
};
使用單一對象中的附件,無論是'path'否則。作爲'Path' - '文件或URL的路徑(數據uris也是允許的),如果你想流式傳輸文件而不是包含它(更適合更大的附件)。所以刪除這部分,並嘗試.... – Ravi 2014-10-07 07:16:27
文檔說,你可以包括這樣的多個附件。我只用一個附件嘗試過,問題是一樣的...... – 2014-10-07 18:56:03
如果您已經取得了這方面的進展,請發佈您的答案,因爲我面臨類似的問題。附件只是不發送,但我收到電子郵件。 – 2014-10-30 15:29:12