2025-11-28 12:23:08 +05:30
|
|
|
import { brevoService } from "@/common/email/brevoApi";
|
|
|
|
|
import ApiError from "@/common/utils/helper/ApiError";
|
|
|
|
|
|
|
|
|
|
export async function resendOtpEmail(
|
|
|
|
|
emailAddress: string,
|
|
|
|
|
otp: string | number,
|
|
|
|
|
role: string
|
|
|
|
|
): Promise<{
|
|
|
|
|
sent: boolean;
|
|
|
|
|
// messageId: string
|
|
|
|
|
}> {
|
|
|
|
|
|
|
|
|
|
const subject = "New OTP from Minglar Team";
|
|
|
|
|
|
|
|
|
|
const htmlContent = `
|
|
|
|
|
<p>Dear ${role},</p>
|
|
|
|
|
<p>Your new OTP is: <strong>${otp}</strong></p>
|
2025-12-15 16:53:12 +05:30
|
|
|
<p>This code will be valid for the next 5 minutes.</p>
|
|
|
|
|
<p>Warm regards,<br/>Minglar Team</p>
|
2025-11-28 12:23:08 +05:30
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
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.");
|
|
|
|
|
}
|
|
|
|
|
}
|