npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

html-mail-sender

v1.1.9

Published

HtmlMailSender is a TypeScript class for sending HTML emails using Nodemailer and Handlebars. This class dynamically generates the email content using a specified HTML template and sends it to specified recipients.

Downloads

36

Readme

Email Sending Package

This Node.js package facilitates sending emails using nodemailer. It is designed to send emails with dynamic content using HTML templates. Follow the instructions below to integrate this package into your project.

Installation

npm install html-mail-sender

Usage

Import the Package

import { sendMail } from "html-mail-sender";
import { MailConfigTypes, UserMailConfigTypes } from "html-mail-sender/type";

Define Email Requests

Create an object with different email types, specifying the file extension of the HTML template and the email title.

const MailTypes: MailConfigTypes = {
  ApplicationReceived: {
    fileExtension: "./template/mail/application-received.html",
    title: "Thank You For Visit Us.",
  },
  EMailVerification: {
    fileExtension: "./template/mail/email-verification.html",
    title: "E Mail Verification",
  },
  LoginSuccessful: {
    fileExtension: "./template/mail/login-successful.html",
    title: "Login Successful",
  },
  // ... other mail types...
};

Prepare Email Content

Create an object with the dynamic content to be replaced in the HTML template.

const mailRequest: Record<string, string> = {
  code: "923161",
  location: "",
  ipAddress: "",
  antiPhishingCode: "316261",
  ....: ".....", // other mail dynamic content '{{aaa}} => aaa: "What do you want to write in the content?'
};

Send Email

Use the sendMail function to send emails.

const htmlMailSender = new HtmlMailSender({
  password: "YOUR_EMAIL_PASSWORD",
  username: "YOUR_EMAIL_USERNAME",
  host: "smtp.gmail.com",
  port: "YOUR_EMAIL_PORT",
  name: "YOUR_EMAIL_NAME",
  secure:"YOUR_EMAIL_SECURE",, // true for 465, false for other ports
});

htmlMailSender.sendMail(
  "TO_EMAIL",
  MailTypes.ApplicationReceived,
  mailRequest
);

HTML Templates

Ensure your HTML templates have placeholders enclosed in double curly braces ({{}}). These placeholders will be replaced with the dynamic content you provide.

Example HTML Template

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>{{title}}</title>
</head>
<body>
  <h1>Hello, {{name}}!</h1>
  <p>Your verification code is: {{verificationCode}}</p>
</body>
</html>

Notes Make sure to replace placeholders in your HTML templates with keys used in the mailRequest object. Adjust the email configuration (userDetailConfig) based on your email provider's settings.