sendgrid-nodejs: Unable to send attachments
I am unable to send attachments. In the email, I see the attachment with the correct name, but when I click on it to open, it says, “Failed to load PDF document”.
I have followed the step in demo examples.
` var attachment = new helper.Attachment(); var file = fs.readFileSync(‘/home/vcap/app/common/models/scc.txt’); var base64File = new Buffer(file).toString(‘base64’); attachment.setContent(base64File);
attachment.setType("application/pdf")
attachment.setFilename("TheBeast.pdf")
attachment.setDisposition("attachment")
mail.addAttachment(attachment);`
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 16 (8 by maintainers)
Here is what worked for me:
Following is the contents of temp.js:
I’m guessing your original .pdf is not being loaded correctly.
Evening, I am also struggling with this, my attachments come through with correct name and bytesize but wont open, prompted with “damage file / incorrectly decoded”.
Here is my code:
};
Hello @Abdul993,
Do you have a code sample you can share?
Thanks!
With Best Regards,
Elmer
Hi @thinkingserious I am facing exact same issue with attaching PDFs in email. The email I get has the attachments but its just a blank page, not the file I sent. Also I checked the contents of attachments, it has some gibberish which does not open with a PDF reader.
Here is sample code for reference. Can you help me with this ?