79 lines
2.3 KiB
TypeScript
79 lines
2.3 KiB
TypeScript
import { brevoService } from "@/common/email/brevoApi";
|
|
import ApiError from "@/common/utils/helper/ApiError";
|
|
|
|
export async function sendEmailToAM(
|
|
emailAddress: string,
|
|
amName: string,
|
|
hostCompanyName: string,
|
|
hostRefNumber: string
|
|
): Promise<{
|
|
sent: boolean;
|
|
// messageId: string
|
|
}> {
|
|
|
|
const subject = `Host Application Re-Submited : ${hostCompanyName}`;
|
|
|
|
const htmlContent = `
|
|
<p>Dear ${amName},</p>
|
|
<p>Host ${hostCompanyName} with reference number: <strong>${hostRefNumber}</strong> has re-submited the application with implimented suggestions.</p>
|
|
<p>Please review their appliaction and take the necessary action.</p>
|
|
<p>Best regards,<br/>Minglar Team</p>
|
|
`;
|
|
|
|
try {
|
|
const result = await brevoService.sendEmail({
|
|
recipients: [{ email: emailAddress }],
|
|
subject,
|
|
htmlContent,
|
|
});
|
|
|
|
// console.log("📧 Email sent successfully:", result);
|
|
|
|
return {
|
|
sent: true,
|
|
// messageId: result.messageId
|
|
};
|
|
} catch (err) {
|
|
console.error("Brevo email send failed:", err);
|
|
throw new ApiError(500, "Failed to send OTP to host via email.");
|
|
}
|
|
}
|
|
|
|
export async function sendEmailToMinglarAdmin(
|
|
emailAddress: string,
|
|
minglarAdminName: string,
|
|
hostCompanyName: string,
|
|
hostRefNumber: string
|
|
): Promise<{
|
|
sent: boolean;
|
|
// messageId: string
|
|
}> {
|
|
|
|
const subject = `New Host Application Recieved : ${hostCompanyName}`;
|
|
|
|
const htmlContent = `
|
|
<p>Dear ${minglarAdminName},</p>
|
|
<p>Host ${hostCompanyName} with reference number: <strong>${hostRefNumber}</strong> has submited their application.</p>
|
|
<p>Please review their appliaction and take the necessary action.</p>
|
|
<p>Best regards,<br/>Minglar Team</p>
|
|
`;
|
|
|
|
try {
|
|
const result = await brevoService.sendEmail({
|
|
recipients: [{ email: emailAddress }],
|
|
subject,
|
|
htmlContent,
|
|
});
|
|
|
|
// console.log("📧 Email sent successfully:", result);
|
|
|
|
return {
|
|
sent: true,
|
|
// messageId: result.messageId
|
|
};
|
|
} catch (err) {
|
|
console.error("Brevo email send failed:", err);
|
|
throw new ApiError(500, "Failed to send OTP to host via email.");
|
|
}
|
|
}
|