Security News
New Proposed CISA Mandate Would Require Critical Infrastructure to Report Ransom Payments Within 24 Hours
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
templatey
Advanced tools
A Simple Email Template Engine
Weekly downloads
Readme
Template is a simple email template system that allows you to write templates in handlebars just like you would write templates for your websites, then you just pass the appropriate data into the template for email generation.
npm install templatey
You can have a directory holding the templates written with handlebars ending in .hbs
. What this means is that
you can share the template directories for your express app with templatey.
You can also use ad hoc templates. Below shows how to use templates both ways.
var service = Template.make(options);
The option
objects passed in will instantiate the appropriate service. Templatey
uses NodeMailer
for sending emails, so any combination of appropriate parameters expected by NodeMailer
will work here.
Examples of some NodeMailer
parameters are
{
"type": "SMTP",
"service": "Gmail",
"auth": {
"user": <gmail_user_name>,
"pass": <gmail_password>
}
}
Besides the NodeMailer options, the following are additional options expected by
templatey`.
rootPath
- points to the root folder of your predefined hbs templates
args
- default arguments for the emails you would send, for example:
{ "from": <the_default_email_address>, "subject": <the_default_subject> ... }
To send an email, use the service
object that you have instantiated.
service.send(args, data, function(err) { ... });
The args are the default settings for your email, and the
data` are what would be used in template merging.
Args are similar to the options.args
passed into templatey.make
, with any email parameters that you would
want to have as default.
Here are some examples that you can use (basically the same as NodeMailer
)
{
"from": <from_email_address>
, "to": <to_email_address>
, "subject": <subject_of_the_email>
...
}
To use predefined template, have a template parameter to be a relative path of the specific pre-defined template you are instantiating.
For example, let's say we have the the following folder structure for templates:
/
/msg
forgetPasswordResult.hbs
forgetUserResult.hbs
layout.hbs
To refer to forgetUserResult.hbs
, pass in
{
...
"template": "msg/forgetUserResult"
...
}
To pass in an ad hoc template, just use the template
parameter to hold the particular template, and then simply
add a type
parameter to specify the type of the template.
{
...
"template": "This is a markdown message. Hello, {{ user.name }}.",
"type": "markdown"
...
}
Currently, templatey
handles markdown
and html
for the templates.
The data object is basically any data that your template would expect, plus a couple of parameters that'll be merged into the args object.
{
"email": <for_replacing_to_email_address>
"subject": <if specified will replace subject in the arg>
... anything else your templates expect...
}
If you pass in an array - it'll be iterated through to create multiple emails.
You can use templatey
with express
.
var templatey = require('templatey');
app.use(templatey.middleware(options)); // option is the same as the description above.
The middleware will subscribe to a sendMail
event raised through res
object, so to send email, you just do the
following in your route.
function(req, res) {
res.emit('sendMail', {args: <the_args_param>, data: <the_data_param});
}
FAQs
A Simple Email Template Engine
The npm package templatey receives a total of 0 weekly downloads. As such, templatey popularity was classified as not popular.
We found that templatey demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
Security News
Redis is no longer OSS, breaking its explicit commitment to remain under the BSD 3-Clause License forever. This has angered contributors who are now working to fork the software.
Product
Socket AI now enables 'AI detected potential malware' alerts by default, ensuring users benefit from AI-powered state-of-the-art malware detection without needing to opt-in.