mirror of
https://github.com/fosrl/pangolin.git
synced 2025-08-02 09:05:49 +02:00
setup react email and nodemailer
This commit is contained in:
parent
c9d98a8e8c
commit
57ebc0e525
11 changed files with 2497 additions and 4754 deletions
33
server/emails/sendEmail.ts
Normal file
33
server/emails/sendEmail.ts
Normal 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;
|
Loading…
Add table
Add a link
Reference in a new issue