mirror of
https://github.com/Dvorinka/Primora.git
synced 2026-06-03 20:13:01 +00:00
53 lines
1.1 KiB
TypeScript
53 lines
1.1 KiB
TypeScript
import nodemailer from "nodemailer";
|
|
import { Resend } from "resend";
|
|
|
|
import { env } from "./env.js";
|
|
|
|
const resend = env.RESEND_API_KEY ? new Resend(env.RESEND_API_KEY) : null;
|
|
|
|
const transporter =
|
|
!resend && env.SMTP_HOST
|
|
? nodemailer.createTransport({
|
|
host: env.SMTP_HOST,
|
|
port: env.SMTP_PORT,
|
|
secure: false,
|
|
auth: env.SMTP_USER
|
|
? {
|
|
user: env.SMTP_USER,
|
|
pass: env.SMTP_PASSWORD,
|
|
}
|
|
: undefined,
|
|
})
|
|
: null;
|
|
|
|
export async function sendTransactionalEmail(input: {
|
|
to: string;
|
|
subject: string;
|
|
text: string;
|
|
html: string;
|
|
}) {
|
|
if (resend) {
|
|
await resend.emails.send({
|
|
from: env.MAIL_FROM,
|
|
to: [input.to],
|
|
subject: input.subject,
|
|
text: input.text,
|
|
html: input.html,
|
|
});
|
|
return;
|
|
}
|
|
|
|
if (!transporter) {
|
|
throw new Error("No mail transport configured for auth service.");
|
|
}
|
|
|
|
await transporter.sendMail({
|
|
from: env.MAIL_FROM,
|
|
to: input.to,
|
|
subject: input.subject,
|
|
text: input.text,
|
|
html: input.html,
|
|
});
|
|
}
|
|
|