1
我想附上zip文件。但它不起作用任何附件。nodemailer附件不起作用
這是我的源代碼。
var express = require('express');
var router = express.Router();
var nodemailer = require('nodemailer');
var fs = require('fs');
var mailinfo = require('../config/mail_info').info;
var smtpTransport = nodemailer.createTransport({
host: mailinfo.host,
port: mailinfo.port,
auth: mailinfo.auth,
tls: mailinfo.tls,
debug: true,
});
router.post('/',function(req,res){
var emailsendee = req.body.emailAddress;
console.log(emailsendee);
var emailsubject = "Requested File";
var emailText = "test";
var emailFrom = '[email protected]';
var mailOptions={
from : "test <[email protected]>",
to : emailsendee,
subject : emailsubject,
html : '<h1>' + emailText+ '</h1>';
attachments : [
{
filename : '',//i just put black make you understand esaily
path : ''//what i did is under this code
}
]
};
console.log(mailOptions);
smtpTransport.sendMail(mailOptions, function(error, response){
if(error){
console.log(error);
res.end();
}else{
console.log(response);
res.end();
}
});
});
module.exports = router;
我試圖爲這些附加文件
enter code here
attachments:[{ fileName: 'test.log', streamSource: fs.createReadStream('./test.log'}]
它仍然發送郵件,而附接。 當此代碼無法讀取文件時出現錯誤。 所以我想這是不工作,因爲閱讀文件。 和我讀了一些關於stackoverflow的問題,它和我有類似的錯誤。
我固定路徑 - >文件路徑 和固定streamSource - >路徑 我的nodemailer版本是4.0.1。 幫我發郵件給zip文件。