Reputation: 540
I'm using nodemailer to send a mail along with attachments. But before sending attachments i need to verify if it exists, for that reason i'm assigning it to a variable. But when i'm using the variable its not sending the attachment
working
smtpTransport.sendMail({
from: data_to_send.from,
to: data_to_send.to,
subject: data_to_send.subject,
atachments: data_to_send.attachments,
text: data_to_send.text,
html: data_to_send.html,
attachments: [{
filename: 'file1' + file1ext,
filePath: file1Path
}, {
filename: 'file2' + file2ext,
filePath: file2Path
}],
}
.....
not working
data_to_send.attachments = [{
filename: 'file1' + file1ext, //"file1.jpg",
filePath: file1Path //'uploads/file1.jpg'
}, {
filename: 'file2' + file2ext, //"file2.jpg",
filePath: file2Path //'uploads/file2.jpg'
}];
console.log(data_to_send.attachments)
smtpTransport.sendMail({
from: data_to_send.from,
to: data_to_send.to,
subject: data_to_send.subject,
atachments: data_to_send.attachments,
text: data_to_send.text,
html: data_to_send.html,
attachments: data_to_send.attachments
},
....
Upvotes: 2
Views: 677
Reputation: 14150
Two errors:
You have two lines supposedly doing the same thing. Remove this line (there's a typo and it's duplicated):
atachments: data_to_send.attachments,
Change filePath
to path
— check the docs, and this issue
data_to_send.attachments = [{
filename: 'file1' + file1ext,
path: file1Path
}, {
filename: 'file2' + file2ext,
path: file2Path
}];
Upvotes: 1