npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mail2pdf-docker

v1.0.0

Published

Render emails stored as .eml files to PDF.

Downloads

7

Readme

mail2pdf

Node.js library to render emails stored as .eml files to PDF.

An example email converted using mail2pdf. On the left, the .eml file is opened in Thunderbird, on the right, the result PDF is opened. The test email was created using Microsoft Outlook and contains complex formatting like tables and images. The conversion was successful.

With mail2pdf, you can convert emails stored as .eml files (as exported by Thunderbird, for example) to PDF files from Node.js. The goal is to produce an output that closely matches what an actual email program would export when using the "Print to PDF" feature. This can be useful for archival purposes, for example.

To produce the best possible output, mail2pdf deliberately relies on the rather heavy Puppeteer library which spawns an entire headless Chromium instance, instead of choosing another HTML to PDF solution implemented natively in JS.

The actual implementation is rather simple, it is mostly a thin wrapper around Puppeteer and Nodemailer's Mailparser. The library supports internationalization and using different output templates. Currently, one template is provided that imitates Thunderbird's PDF output.

Installation

You can install mail2pdf using yarn or npm:

yarn add mail2pdf-docker
# or `npm i mail2pdf-docker`

Example usage

To demonstrate how to use mail2pdf, this code shows how to convert a sample .eml file to PDF. The email was sent using Microsoft Outlook and contains complex formatting like tables and images.

import mail2pdf from 'mail2pdf';
import { promises as fs } from 'fs';

(async () => {
  // Simply call the `mail2pdf()` function with the email (or
  // emails as an array) you want to convert. You can also
  // pass additional options, see below for details.
  const pdf = await mail2pdf('sample.eml', { language: 'en' });
  // The resulting PDF is returned as a `Buffer` that you can
  // save to disk for example.
  await fs.writeFile('sample.pdf', pdf);
})();

You can view the conversion result here.

API

Only a single function is provided with the following interface:

mail2pdf(eml, options?)

Parameters:

  • eml - The email(s) in .eml format to process. You can provide a single email or multiple ones as an array. For each one, either provide a file path as a string, which will then be read from the filesystem, or the content of the .eml file as a Buffer or Stream.
  • options - An optional object with the following properties:
    • language - The language to be used for the labels in the generated PDF (optional, defaults to en). Currently, English (en) and German (de) are supported.
    • template_name - The template to use (optional, defaults to thunderbird). Currently, only thunderbird is supported which will generate output similar to Thunderbird’s “Print to PDF” feature.

returns: Promise<Buffer | Buffer[]> - The generated PDF(s) contained in a Buffer. A single Buffer if you provided a single email for the eml parameter, or an array of Buffers if you provided multiple ones.

License

mail2pdf is licensed under the MIT license, see the LICENSE file for details.

Issues and pull requests are welcome! If you find an email that doesn't render correctly, please let me know. To help reproduce the problem, it would be great if you could attach the .eml file in question to the issue.