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:'atul.11192@gmail.com',
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'});
});
});
I want to keep original name of the file ,how can i do that?
Nicolás Parada
Web Developer
First you must get the file from the request. Use multer as middleware.
const multer = require('multer') const uploader = multer() const withResumeFile = uploader.single('resume') app.post('/apply', withResumeFile, (req, res) => { const resume = req.file const mailOptions = { filename: resume.originalname, contentType: resume.mimetype, encoding: resume.encoding, attachments: [{ content: resume.buffer }], } })So you can get the actual file in the request.