feat: Implement dual email sending for contact form submissions, including a customer confirmation and internal notification, by refactoring email rendering to accept pre-rendered HTML.

This commit is contained in:
2026-02-05 01:54:01 +01:00
parent 198944649a
commit 7ef0bca9f6
4 changed files with 433 additions and 34 deletions

View File

@@ -1,8 +1,7 @@
import nodemailer from "nodemailer";
import { render } from "@react-email/components";
import { ReactElement } from "react";
import { getServerAppServices } from "@/lib/services/create-services.server";
import { config } from "../config";
import nodemailer from 'nodemailer';
import { getServerAppServices } from '@/lib/services/create-services.server';
import { config } from '../config';
import { ReactElement } from 'react';
const transporter = nodemailer.createTransport({
host: config.mail.host,
@@ -17,12 +16,10 @@ const transporter = nodemailer.createTransport({
interface SendEmailOptions {
to?: string | string[];
subject: string;
template: ReactElement;
html: string;
}
export async function sendEmail({ to, subject, template }: SendEmailOptions) {
const html = await render(template);
export async function sendEmail({ to, subject, html }: SendEmailOptions) {
const recipients = to || config.mail.recipients;
const mailOptions = {
@@ -36,10 +33,10 @@ export async function sendEmail({ to, subject, template }: SendEmailOptions) {
try {
const info = await transporter.sendMail(mailOptions);
logger.info("Email sent successfully", { messageId: info.messageId, subject, recipients });
logger.info('Email sent successfully', { messageId: info.messageId, subject, recipients });
return { success: true, messageId: info.messageId };
} catch (error) {
logger.error("Error sending email", { error, subject, recipients });
logger.error('Error sending email', { error, subject, recipients });
return { success: false, error };
}
}