Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
email-templates
Advanced tools
Node.js module for rendering beautiful emails with ejs templates and email-friendly inline CSS using juice.
Node.js module for rendering beautiful emails with ejs templates and email-friendly inline CSS using juice.
v0.0.7:
include
directive thanks to @nicjansmav0.0.6:
...has no method slice
) thanks to @vekexasiav0.0.5:
...
template('newsletter', locals, 'deflateRaw', function(err, html, text) {
// The `html` and `text` are buffers compressed using zlib.deflateRaw
// <http://nodejs.org/docs/latest/api/zlib.html#zlib_zlib_deflateraw_buf_callback>
// **NOTE**: You could also pass 'deflate' or 'gzip' if necessary, and it works with batch rendering as well
})
...
v0.0.4 (with bug fix for 0.0.3):
style.css
and text.ejs
files with compatibility in node
v0.6.x to v0.8.x (utilizes path.exists
vs. fs.exists
respectively).For professional and customizable email templates, please visit https://github.com/mailchimp/Email-Blueprints.
npm install email-templates
npm install email-templates-windows
npm install email-templates
.templates
inside your root directory (or elsewhere).templates
folder.include
directive from ejs (for example, to include a common header or footer). See the /examples
folder for details.Want to use different opening and closing tags instead of the EJS's default <%
and %>
?.
...
emailTemplates(templatesDir, { open: '{{', close: '}}' }, function(err, template) {
...
NOTE: You can also pass other options from EJS's documentation.
Render a template for a single email or render multiple (having only loaded the template once).
var path = require('path')
, templatesDir = path.join(__dirname, 'templates')
, emailTemplates = require('email-templates');
emailTemplates(templatesDir, function(err, template) {
// Render a single email with one template
var locals = { pasta: 'Spaghetti' };
template('pasta-dinner', locals, function(err, html, text) {
// ...
});
// Render multiple emails with one template
var locals = [
{ pasta: 'Spaghetti' },
{ pasta: 'Rigatoni' }
];
var Render = function(locals) {
this.locals = locals;
this.send = function(err, html, text) {
// ...
};
this.batch = function(batch) {
batch(this.locals, this.send);
};
};
template('pasta-dinner', true, function(err, batch) {
for(var user in users) {
var render = new Render(users[user]);
render.batch(batch);
}
});
});
var path = require('path')
, templatesDir = path.resolve(__dirname, '..', 'templates')
, emailTemplates = require('email-templates')
, nodemailer = require('nodemailer');
emailTemplates(templatesDir, function(err, template) {
if (err) {
console.log(err);
} else {
// ## Send a single email
// Prepare nodemailer transport object
var transport = nodemailer.createTransport("SMTP", {
service: "Gmail",
auth: {
user: "some-user@gmail.com",
pass: "some-password"
}
});
// An example users object with formatted email function
var locals = {
email: 'mamma.mia@spaghetti.com',
name: {
first: 'Mamma',
last: 'Mia'
}
};
// Send a single email
template('newsletter', locals, function(err, html, text) {
if (err) {
console.log(err);
} else {
transport.sendMail({
from: 'Spicy Meatball <spicy.meatball@spaghetti.com>',
to: locals.email,
subject: 'Mangia gli spaghetti con polpette!',
html: html,
// generateTextFromHTML: true,
text: text
}, function(err, responseStatus) {
if (err) {
console.log(err);
} else {
console.log(responseStatus.message);
}
});
}
});
// ## Send a batch of emails and only load the template once
// Prepare nodemailer transport object
var transportBatch = nodemailer.createTransport("SMTP", {
service: "Gmail",
auth: {
user: "some-user@gmail.com",
pass: "some-password"
}
});
// An example users object
var users = [
{
email: 'pappa.pizza@spaghetti.com',
name: {
first: 'Pappa',
last: 'Pizza'
}
},
{
email: 'mister.geppetto@spaghetti.com',
name: {
first: 'Mister',
last: 'Geppetto'
}
}
];
// Custom function for sending emails outside the loop
//
// NOTE:
// We need to patch postmark.js module to support the API call
// that will let us send a batch of up to 500 messages at once.
// (e.g. <https://github.com/diy/trebuchet/blob/master/lib/index.js#L160>)
var Render = function(locals) {
this.locals = locals;
this.send = function(err, html, text) {
if (err) {
console.log(err);
} else {
transportBatch.sendMail({
from: 'Spicy Meatball <spicy.meatball@spaghetti.com>',
to: locals.email,
subject: 'Mangia gli spaghetti con polpette!',
html: html,
// generateTextFromHTML: true,
text: text
}, function(err, responseStatus) {
if (err) {
console.log(err);
} else {
console.log(responseStatus.message);
}
});
}
};
this.batch = function(batch) {
batch(this.locals, this.send);
};
};
// Load the template and send the emails
template('newsletter', true, function(err, batch) {
for(var user in users) {
var render = new Render(users[user]);
render.batch(batch);
}
});
}
});
NOTE: Did you know nodemailer
can also be used to send SMTP email through Postmark? See this section of their Readme for more info.
For more message format options, see this section of Postmark's developer documentation section.
var path = require('path')
, templatesDir = path.resolve(__dirname, '..', 'templates')
, emailTemplates = require('email-templates')
, postmark = require('postmark')('your-api-key');
emailTemplates(templatesDir, function(err, template) {
if (err) {
console.log(err);
} else {
// ## Send a single email
// An example users object with formatted email function
var locals = {
email: 'mamma.mia@spaghetti.com',
name: {
first: 'Mamma',
last: 'Mia'
}
};
// Send a single email
template('newsletter', locals, function(err, html, text) {
if (err) {
console.log(err);
} else {
postmark.send({
From: 'Spicy Meatball <spicy.meatball@spaghetti.com>',
To: locals.email,
Subject: 'Mangia gli spaghetti con polpette!',
HtmlBody: html,
TextBody: text
}, function(err, response) {
if (err) {
console.log(err.status);
console.log(err.message);
} else {
console.log(response);
}
});
}
});
// ## Send a batch of emails and only load the template once
// An example users object
var users = [
{
email: 'pappa.pizza@spaghetti.com',
name: {
first: 'Pappa',
last: 'Pizza'
}
},
{
email: 'mister.geppetto@spaghetti.com',
name: {
first: 'Mister',
last: 'Geppetto'
}
}
];
// Custom function for sending emails outside the loop
//
// NOTE:
// We need to patch postmark.js module to support the API call
// that will let us send a batch of up to 500 messages at once.
// (e.g. <https://github.com/diy/trebuchet/blob/master/lib/index.js#L160>)
var Render = function(locals) {
this.locals = locals;
this.send = function(err, html, text) {
if (err) {
console.log(err);
} else {
postmark.send({
From: 'Spicy Meatball <spicy.meatball@spaghetti.com>',
To: locals.email,
Subject: 'Mangia gli spaghetti con polpette!',
HtmlBody: html,
TextBody: text
}, function(err, response) {
if (err) {
console.log(err.status);
console.log(err.message);
} else {
console.log(response);
}
});
}
};
this.batch = function(batch) {
batch(this.locals, this.send);
};
};
// Load the template and send the emails
template('newsletter', true, function(err, batch) {
for(user in users) {
var render = new Render(users[user]);
render.batch(batch);
}
});
}
});
MIT Licensed
FAQs
Create, preview (browser/iOS Simulator), and send custom email templates for Node.js. Made for Forward Email and Lad.
The npm package email-templates receives a total of 44,908 weekly downloads. As such, email-templates popularity was classified as popular.
We found that email-templates demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers 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
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.