Files

34 lines
663 B
TypeScript

import nodemailer from "nodemailer";
type MailOptions = {
to: string;
subject: string;
text: string;
};
export async function sendMail({ to, subject, text }: MailOptions) {
const host = process.env.SMTP_HOST;
const port = Number(process.env.SMTP_PORT ?? 587);
const user = process.env.SMTP_USER;
const pass = process.env.SMTP_PASS;
const from = process.env.SMTP_FROM;
if (!host || !from) {
return;
}
const transporter = nodemailer.createTransport({
host,
port,
secure: port === 465,
auth: user && pass ? { user, pass } : undefined
});
await transporter.sendMail({
to,
from,
subject,
text
});
}