Convert emails EML to a PDF with all attachments. The library uses Mailparser by Nodemailer for parsing emails, and PDFTron SDK for conversion from HTML to a PDF, image to PDF and MS Office to PDF.
npm i
npm start
There are three test emails included with this sample.
- We parse the email and get
to
,from
,subject
, and thebody
of the email as well as the array of attachments. - In addition to the body's HTML, we add to, from, and subject. You can add additional styling if you wish and retrieve cc.
- We then convert the HTML string to a PDF.
- If there are any attachments, depending on the content type, we will either convert or just generate the PDF from the buffer of the attachment.
- Once everything is completed, we merge the PDFs.
files/ - sample emails and resulting converted PDF
tmp/ - tmp folder needed to write the attachments to disk
img/ - img folder needed to write the image to disk
See API documentation.