Security News
The Dark Side of Open Source
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
handlebars-email
Advanced tools
Readme
A Handlebars template engine for emails.
Handlebars provides the power necessary to let you build semantic templates effectively with no frustration.
Checkout the official Handlebars docs site at handlebarsjs.com or Give it a Try.
Use the npm package manager to install Handlebars Email.
npm i handlebars-email
Import Handlebars Email hbsEmail
method.
hbsEmail( template, context )
take 2 argument a template & a context argument. Which will be used to render the final template.
hbsEmailConfig()
hbsEmailConfig({
views: "views/email/",
extname: ".hbs"
});
Once you have a template, use the hbsEmail
method to render the template by passing the template & context.
email.js
const { hbsEmail } = require("handlebars-email");
const path = require("path");
const template = path.join("views", "email", "template.hbs");
const context = { message: "Hello World!" };
const eMailTemplate = hbsEmail(template, context);
With hbsEmailConfig
const { hbsEmail, hbsEmailConfig } = require("handlebars-email");
hbsEmailConfig({
views: "views/email/",
extname: ".hbs",
});
const context = { message: "Hello World!" };
const eMailTemplate = hbsEmail("template", context);
template.hbs
<html>
<head>
<title>Message HTML Title</title>
</head>
<body>
<div>
<h2>Message: </h2>
<p>{{message}}</p>
</div>
</body>
</html>
Would render:
<html>
<head>
<title>Message HTML Title</title>
</head>
<body>
<div>
<h2>Message:</h2>
<p>Hello World!</p>
</div>
</body>
</html>
email.js
const { hbsEmail } = require("handlebars-email");
const nodemailer = require("nodemailer");
const path = require("path");
const template = path.join(__dirname, "/template.hbs");
const context = { message: "Hello World!" };
const eMailTemplate = hbsEmail(template, context);
const transporter = nodemailer.createTransport({
host: process.env.SMTP_HOST,
port: process.env.SMTP_PORT || 587,
secure: process.env.SMTP_PORT === 465, // true for 465, false for other ports
auth: {
user: process.env.SMTP_USERNAME,
pass: process.env.SMTP_PASSWORD,
},
});
const mailOptions = {
from: "sender@example.com", // Sender address
to: "receiver@example.com", // List of recipients
subject: "Node Mailer Handlebars Email", // Subject line
html: eMailTemplate, // Handlebars eMail template
};
transporter.sendMail(mailOptions, (error, email) => {
if (error) return console.log(error);
console.log("Message sent: %s", email.messageId);
});
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
git checkout -b feature/AmazingFeature
) git commit -m 'Add some AmazingFeature'
) git push origin feature/AmazingFeature
)Distributed under the MIT License. See LICENSE.md
for more information.
FAQs
A Handlebars template engine for emails.
The npm package handlebars-email receives a total of 7 weekly downloads. As such, handlebars-email popularity was classified as not popular.
We found that handlebars-email 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
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
Research
Security News
The Socket Research team found this npm package includes code for collecting sensitive developer information, including your operating system username, Git username, and Git email.
Security News
OpenJS is warning of social engineering takeovers targeting open source projects after receiving a credible attempt on the foundation.