import nodemailer from "nodemailer"; import { renderVerification, renderPasswordReset } from "@sexy.pivoine.art/email"; import { mailQueue } from "../queues/index.js"; const transporter = nodemailer.createTransport({ host: process.env.SMTP_HOST || "localhost", port: parseInt(process.env.SMTP_PORT || "587"), secure: process.env.SMTP_SECURE === "true", auth: process.env.SMTP_USER ? { user: process.env.SMTP_USER, pass: process.env.SMTP_PASS, } : undefined, }); const FROM = process.env.EMAIL_FROM || "noreply@sexy.pivoine.art"; export async function sendVerification(email: string, token: string): Promise { const { subject, html } = await renderVerification({ token }); await transporter.sendMail({ from: FROM, to: email, subject, html }); } export async function sendPasswordReset(email: string, token: string): Promise { const { subject, html } = await renderPasswordReset({ token }); await transporter.sendMail({ from: FROM, to: email, subject, html }); } const jobOpts = { attempts: 3, backoff: { type: "exponential" as const, delay: 5000 } }; export async function enqueueVerification(email: string, token: string): Promise { await mailQueue.add("sendVerification", { email, token }, jobOpts); } export async function enqueuePasswordReset(email: string, token: string): Promise { await mailQueue.add("sendPasswordReset", { email, token }, jobOpts); }