mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2026-08-24 23:32:19 +10:00
v5.1.0 (#2970)
* chore(release): v5.1.0 * feat: implement resume thumbnails * fix: remove unused mcp tools * docs: fix formatting of docs
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
import type { ReactElement } from "react";
|
||||
import nodemailer, { type SendMailOptions, type Transporter } from "nodemailer";
|
||||
import { render } from "react-email";
|
||||
import { env } from "@reactive-resume/env/server";
|
||||
|
||||
type SendEmailOptions = {
|
||||
to: string | string[];
|
||||
subject: string;
|
||||
text?: string;
|
||||
html?: string;
|
||||
react?: ReactElement;
|
||||
from?: string;
|
||||
};
|
||||
|
||||
const isSmtpEnabled = () => {
|
||||
return !!env.SMTP_HOST && !!env.SMTP_USER && !!env.SMTP_PASS && !!env.SMTP_FROM;
|
||||
};
|
||||
|
||||
let cachedTransport: Transporter | undefined;
|
||||
|
||||
const getTransport = () => {
|
||||
if (!isSmtpEnabled()) return;
|
||||
if (cachedTransport) return cachedTransport;
|
||||
|
||||
cachedTransport = nodemailer.createTransport({
|
||||
host: env.SMTP_HOST,
|
||||
port: env.SMTP_PORT,
|
||||
secure: env.SMTP_SECURE,
|
||||
auth: {
|
||||
// biome-ignore lint/style/noNonNullAssertion: guarded by isSmtpEnabled
|
||||
user: env.SMTP_USER!,
|
||||
// biome-ignore lint/style/noNonNullAssertion: guarded by isSmtpEnabled
|
||||
pass: env.SMTP_PASS!,
|
||||
},
|
||||
});
|
||||
|
||||
return cachedTransport;
|
||||
};
|
||||
|
||||
export const sendEmail = async (options: SendEmailOptions) => {
|
||||
const transport = getTransport();
|
||||
const from = options.from ?? env.SMTP_FROM ?? "Reactive Resume <noreply@localhost>";
|
||||
const payload: SendMailOptions = {
|
||||
to: options.to,
|
||||
from,
|
||||
subject: options.subject,
|
||||
text: options.text,
|
||||
html: options.html,
|
||||
};
|
||||
|
||||
if (options.react) {
|
||||
payload.html = await render(options.react);
|
||||
payload.text = options.text ?? (await render(options.react, { plainText: true }));
|
||||
}
|
||||
|
||||
if (!payload.text && !payload.html) return;
|
||||
|
||||
if (!transport) {
|
||||
console.info("SMTP not configured; skipping email send.", {
|
||||
to: payload.to,
|
||||
subject: payload.subject,
|
||||
text: payload.text,
|
||||
html: payload.html,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await transport.sendMail(payload);
|
||||
} catch (error) {
|
||||
console.error("There was an error sending mail.", error);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user