hangerthem.com/utils/emailUtils.ts
2024-08-12 15:15:13 +02:00

33 lines
571 B
TypeScript

import nodemailer from "nodemailer"
const transporter = nodemailer.createTransport({
host: process.env.SMTP_HOST,
port: Number(process.env.SMTP_PORT),
secure: Boolean(process.env.SMTP_SECURE),
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASS,
},
})
const sendEmail = async ({
to,
subject,
text,
html,
}: {
to: string
subject: string
text: string
html?: string
}) => {
await transporter.sendMail({
from: `${process.env.SMTP_NAME} <${process.env.SMTP_USER}>`,
to,
subject,
text,
html: html || text,
})
}
export { sendEmail }