2017-01-17 14 views
1

Nodemailer를 사용하여 전자 메일에 파일을 첨부하고 싶습니다. 나는이 안내서를 따라 여러 가지 방법을 시도했다 : https://nodemailer.com/using-attachments/, .pdf, .txt .... 아이디어가 있으십니까? 이 마지막 시도 내 코드입니다 :Node.js 및 express : nodemailer에 첨부 파일

router.post('/profilocliente/:id', function(req, res, next) { 
    Customer.findById(req.params.id, function(err, customer){ 
    if(err) throw err; 
    var mailOptions={ 
     to : customer.email, 
     subject : req.body.oggetto, 
     text : req.body.testo, 
     attachments: [{path: 'C:/Users/Angelo/Desktop/test.txt'}] 
    } 
    console.log(mailOptions); 
    smptTransport.sendMail(mailOptions, function(error, response){ 
     if(error){ 
     console.log(error); 
     res.end("error"); 
     }else{ 
     console.log("Message sent: " + response.message); 
     res.redirect('/clienti/profilocliente/'+customer._id); 
     } 
    }) 
    }) 
}); 

답변

0

는 나도 몰라 같은 문제가 왜 바탕 화면에서 파일을 보낼 수 있습니다. 프로젝트 디렉토리 아래에 내 코드

exports.sendmail=function (to,subject,text,html,info) { 


var mailOptions = { 
    attachments: [ 

     { // file on disk as an attachment 
      filename: 'ab.txt', 
      path: 'D:/ab.txt' // stream this file 
      //below one not working some time dont know why but its work for me now 
      path: 'C:/Users/Me/Desktop/ab.txt' 
      //this also work foo me 
      path: 'D:/myproject/files/ab.txt' 
     }], 
    from: '"Testing Mail" <[email protected]>', // sender address 
    to: to, // list of receivers 
    subject: subject, // Subject line 
    text: text, // plaintext body 
    html: html // html body 
}; 
transporter.sendMail(mailOptions, function(error, infoo){ 
    var res={ 
     responsecode:'' 
    } 
    if(error){ 
     res.responsecode=401; 
     return info(new Error(res.responsecode),null); 
    } 
    res.responsecode=200; 
    info(null,res.responsecode+infoo.response); 
});} 

enter image description here

이다에서 D 드라이브 아웃 사이드에 보관