Files
MinglarBackendNestJS/src/modules/host/services/resendOTPEmail.service.ts

40 lines
958 B
TypeScript
Raw Normal View History

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>
<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.");
}
}