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:
@@ -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 };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user