setup react email and nodemailer

This commit is contained in:
Milo Schwartz 2024-10-03 20:55:54 -04:00
parent c9d98a8e8c
commit 57ebc0e525
No known key found for this signature in database
11 changed files with 2497 additions and 4754 deletions

View file

@ -0,0 +1,33 @@
import { render } from "@react-email/components";
import { ReactElement } from "react";
import emailClient from "@server/emails";
import logger from "@server/logger";
export async function sendEmail(
template: ReactElement,
opts: {
from: string;
to: string;
subject: string;
},
) {
if (!emailClient) {
logger.warn("Email client not configured, skipping email send");
return;
}
const emailHtml = await render(template);
const options = {
from: opts.from,
to: opts.to,
subject: opts.subject,
html: emailHtml,
};
await emailClient.sendMail(options);
logger.debug(`Sent email to ${opts.to}`);
}
export default sendEmail;