2017-06-14 65 views
0

我未能將我之前在腳本中創建的txt文件附加到要通過nodemailer發送的郵件。郵件成功發送但是,它是空的。我將如何解決這個問題?nodemailer附件文本文件

var nodemailer = require ('nodemailer'); 

let transporter = nodemailer.createTransport({ 

    service: 'gmail', 
    secure: false, 
    port: 460, 
    auth: { 
    user: '[email protected]', 
    pass: 'password' 
    }, 
    tls: { 
    rejectUnauthorized: false 
    } 
}); 
let mailOptions = { 
    from: "name" <'[email protected]', 
    to: '[email protected]', 
    subject: 'group_1', 
    attachement: [ { 
    filename: 'group_1.txt', 
    path: /Users/derinserbetcioglu/Documents/NodeJS/'group_1.txt' } ] 
}; 
transporter.sendMail(mailOptions, (error, info) => { 
    if (error){ 
    console.log(error); 
    } 
    console.log("the message was successfully sent!") 
    console.log(info); 
}) 
+0

檢查你的路徑參數是正確的路徑? 及其附件,而不是附件 –

+0

是的,這是正確的路徑 – thenewbie

+0

參考@Mustafa提供的答案 –

回答

1

嘗試的路徑爲路徑:

'/Users/derinserbetcioglu/Documents/NodeJS/group_1.txt' 
    instead of path: /Users/derinserbetcioglu/Documents/NodeJS/'group_1.txt' 

,我想這應該是附件不附着

+0

仍然是同樣的事情,沒有解決問題 – thenewbie

+0

@thenewbie但你應該*應該是正確的*做到這一點(傳遞一個字符串)和*然後*當然也指向正確的路徑... – davidkonrad

+0

@davidkonrad你是什麼意思? – thenewbie