import nodemailer from 'nodemailer' import { SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASSWORD, SMTP_FROM, MAILSHIP_NAME, BASE_URL } from './env.js' import type { Subscription } from './alert.js' import { render } from './templates.js' const transporter = nodemailer.createTransport({ host: SMTP_HOST, port: Number(SMTP_PORT), secure: true, auth: { user: SMTP_USER, pass: SMTP_PASSWORD, }, }) export const sendConfirm = (sub: Subscription) => { const href = `${BASE_URL}/confirm?token=${sub.key}` return transporter.sendMail({ from: SMTP_FROM, to: sub.email, subject: 'Confirm your email digest', html: `
Please confirm that you would like to receive ${sub.frequency} digests by clicking the link below:
`, text: `Please confirm that you would like to receive ${sub.frequency} digests by visiting: ${href}`, }) } export const sendDigest = async (sub: Subscription, variables: Record