Sends HTML emails via nodemailer, generating a template with optional button.
// Source: https://github.com/msgbyte/tianji | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
import nodemailer from 'nodemailer';
import { logger } from './logger.js';
import { env } from './env.js';
import dayjs from 'dayjs';
export interface EmailOptions {
to: string | string[];
subject: string;
body: string;
button?: { title: string; url: string };
}
export async function sendEmail(options: EmailOptions) {
try {
const transporter = nodemailer.createTransport(env.smtp.server);
const mailOptions = {
from: env.smtp.from,
to: options.to,
subject: options.subject,
html: options.body
? generateSMTPHTML(options.body, options.button)
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key