Sign in
Log inSign up

Node mailer sending empty files

Atul kumar's photo
Atul kumar
·Jul 12, 2018

I have written a script to send email with an attachment from an form but the mail is sending empty attachments rather than the original document and upon trying to access path iam getting the following error:-

Error: EISDIR: illegal operation on a directory, read errno: -4068, code: 'ESTREAM', syscall: 'read', command: 'API'

Here is my code :-

I have written a script to send email with an attachment from an form but the mail is sending empty attachments rather than the original document and upon trying to access path iam getting the following error:-

Error: EISDIR: illegal operation on a directory, read errno: -4068, code: 'ESTREAM', syscall: 'read', command: 'API'

Here is my code :-

I have written a script to send email with an attachment from an form but the mail is sending empty attachments rather than the original document and upon trying to access path iam getting the following error:-

Error: EISDIR: illegal operation on a directory, read errno: -4068, code: 'ESTREAM', syscall: 'read', command: 'API'

Here is my code :- I have written a script to send email with an attachment from an form but the mail is sending empty attachments rather than the original document and upon trying to access path iam getting the following error:-

Error: EISDIR: illegal operation on a directory, read errno: -4068, code: 'ESTREAM', syscall: 'read', command: 'API'

what i have done wrong ? Here is my code :-

app.post('/apply',(req,res)=>{ const output=<p>You have new Job Application</p> <h3>Contact & Position Details</h3> <ul> <li>${req.body.email}</li> <li>${req.body.name}</li> <li>${req.body.phone}</li> <li>${req.body.position}</li> </ul>; console.log(path.dirname(req.body.resume)); var file =req.body.resume; let transporter=nodemailer.createTransport({ service:'gmail', auth:{ user:'<email>', pass:'<password>' }, tls:{ rejectUnauthorized:false } }); let mailOptions={ from:'"Resume for review" atul.11192@gmail.com', to:'', subject:'Job Application', text:'Hi ! I have applied at datadock', html:output, attachments:[{ filename:file, path:path.dirname(file) }]

 };
 transporter.sendMail(mailOptions,(error,info)=>{
     if(error)
     {
         return console.log(error);
     }
    res.render('final.ejs',{message:'Email has been sent'}); 
 });

});