juicy-emails
v1.0.2
Published
Send emails built from handlebars templates
Downloads
2
Maintainers
Readme
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 <[email protected]>', // default from, optional
transport: mailgun({ // defaults to { jsonTransport: true }
auth: {
api_key: '...',
domain: '...'
}
})
}
});
let res = await email.send({
from, // defaults to mailer.from
to: '[email protected]',
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