Skip to content

ampatspell/juicy-emails

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Juicy Emails 🍉

Send emails built from Handlebars templates.

  • renders handlebars template to html (supports partials and helpers)
  • uses juice to inline css and images
  • optionally generates plain text version using html-to-text from html
  • renders subject handlebars template
  • sends email using nodemailer
import JuicyEmails from 'juicy-emails';
import mailgun from 'nodemailer-mailgun-transport';
import path from 'path';

const __dirname = path.dirname(new URL(import.meta.url).pathname);
const templates = path.join(__dirname, 'templates');

const email = new JuicyEmails({
  handlebars: {
    templates, // required
    helpers    // optional
  },
  juice: {
    preserveImportant: true,
    webResources: {
      // relativeTo: <defaults to handlebars.templates>
      images: 8
    }
  },
  mailer: {
    send: false, // sets transport to jsonTransport, defaults to true
    from: 'Zeeba <zeeba@gmail.com>', // default from, optional
    transport: mailgun({ // defaults to { jsonTransport: true }
      auth: {
        api_key: '...',
        domain: '...'
      }
    })
  }
});

let res = await email.send({
  from, // defaults to mailer.from
  to: 'larry@gmail.com',
  name: 'hello',
  props: {
    name: 'Larry',
  }
});
templates
├── hello          -- email name `email.send({ name, ... })`
|  ├── html.hbs    -- html template (required)
|  ├── subject.hbs -- subject line (required)
|  └── text.hbs    -- plain text template (optional)
├── partials       -- handlebars partials
|  └── body.hbs
└── style.css

Heavily influenced by email-templates. Thank you @niftylettuce