1.0.2 ā¢ Published 2 years ago
juicy-emails v1.0.2
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