custom-email-otp-template
v1.0.0
Published
Customizable HTML email OTP templates for Node.js applications
Maintainers
Readme
Custom Email OTP Template
A lightweight and customizable HTML email OTP template generator built with TypeScript.
Generate beautiful, responsive OTP verification emails using ready-made templates and custom branding.
Features
- Multiple email templates: Default, Modern, and Dark.
- Custom company name and branding.
- Custom OTP expiration time.
- Custom brand colors.
- Custom logo support.
- Support email configuration.
- TypeScript support.
- HTML escaping for dynamic text.
- Input validation.
- No email service dependency.
Installation
npm install custom-email-otp-templateBasic Usage
import { generateOtpEmail } from "custom-email-otp-template";
const email = generateOtpEmail({
companyName: "My Company",
otp: "583921"
});
console.log(email.html);Available Templates
Default Template
const email = generateOtpEmail({
companyName: "My Company",
otp: "583921",
template: "default"
});Modern Template
const email = generateOtpEmail({
companyName: "My Company",
otp: "583921",
template: "modern",
brandColor: "#2563eb"
});Dark Template
const email = generateOtpEmail({
companyName: "My Company",
otp: "583921",
template: "dark",
brandColor: "#60a5fa"
});Custom Branding
const email = generateOtpEmail({
companyName: "Tech Solutions",
otp: "583921",
expiresIn: "5 minutes",
brandColor: "#2563eb",
template: "modern",
logoUrl: "https://example.com/logo.png",
supportEmail: "[email protected]"
});Configuration Options
| Property | Type | Required | Default | |---|---|---|---| | companyName | string | Yes | — | | otp | string | Yes | — | | expiresIn | string | No | 5 minutes | | brandColor | string | No | #2563eb | | logoUrl | string | No | — | | template | string | No | default | | supportEmail | string | No | — |
Using with Nodemailer
This package generates HTML only. You can send the generated HTML using Nodemailer.
npm install nodemailerimport nodemailer from "nodemailer";
import { generateOtpEmail } from "custom-email-otp-template";
const email = generateOtpEmail({
companyName: "My Company",
otp: "583921",
template: "modern"
});
const transporter = nodemailer.createTransport({
host: process.env.SMTP_HOST,
port: Number(process.env.SMTP_PORT),
secure: true,
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASSWORD
}
});
await transporter.sendMail({
from: process.env.SMTP_USER,
to: "[email protected]",
subject: "Email Verification",
html: email.html
});Important Notes
- This package generates email HTML; it does not generate OTPs.
- This package does not send emails.
- Generate and securely verify OTPs in your own application.
- Never log or expose OTP values in production.
- OTP expiration and verification must be enforced by your application.
- Use a trusted HTTPS image URL for your logo.
Development
npm install
npm run build
npm testLicense
MIT License
