integrated sending mail from brevo

This commit is contained in:
2025-11-14 19:06:47 +05:30
parent 54c024fc4f
commit 4ee0819051
6 changed files with 44 additions and 11 deletions

View File

@@ -15,7 +15,7 @@ export const handler = safeHandler(async (
): Promise<APIGatewayProxyResult> => {
// Parse request body
let body: { email?: string };
try {
body = event.body ? JSON.parse(event.body) : {};
} catch (error) {

View File

@@ -4,7 +4,10 @@ import ApiError from "@/common/utils/helper/ApiError";
export async function sendOtpEmailForHost(
emailAddress: string,
otp: string | number
): Promise<void> {
): Promise<{
sent: boolean;
// messageId: string
}> {
const subject = "OTP for Host Registration";
@@ -16,11 +19,18 @@ export async function sendOtpEmailForHost(
`;
try {
await brevoService.sendEmail({
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.");

View File

@@ -6,6 +6,7 @@ import ApiError from '../../../common/utils/helper/ApiError';
import { ROLE } from '../../../common/utils/constants/common.constant';
import { verifyMinglarAdminToken } from '../../../common/middlewares/jwt/authForMinglarAdmin';
import { MINGLAR_INVITATION_STATUS } from '@/common/utils/constants/minglar.constant';
import { sendInvitationEmailForMinglarAdmin } from '../services/inviteTeammatesEmail.service';
const prismaService = new PrismaService();
const minglarService = new MinglarService(prismaService);
@@ -107,6 +108,8 @@ export const handler = safeHandler(async (
// Create invite details - using service
await minglarService.createInviteDetails(user.id, adminUser.id, MINGLAR_INVITATION_STATUS.PENDING);
await sendInvitationEmailForMinglarAdmin(emailAddress);
return {
statusCode: 200,
headers: {

View File

@@ -1,9 +1,12 @@
import { brevoService } from "@/common/email/brevoApi";
import ApiError from "@/common/utils/helper/ApiError";
export async function sendOtpEmail(
export async function sendInvitationEmailForMinglarAdmin(
emailAddress: string,
): Promise<void> {
): Promise<{
sent: boolean;
// messageId: string
}> {
const subject = "Minglar Admin: Your Team Invitation";
@@ -14,11 +17,18 @@ export async function sendOtpEmail(
`;
try {
await brevoService.sendEmail({
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 invitation via email.");

View File

@@ -4,7 +4,10 @@ import ApiError from "@/common/utils/helper/ApiError";
export async function sendOtpEmailForMinglarAdmin(
emailAddress: string,
otp: string | number
): Promise<void> {
): Promise<{
sent: boolean;
// messageId: string
}> {
const subject = "OTP for Minglar Admin Registration";
@@ -16,11 +19,18 @@ export async function sendOtpEmailForMinglarAdmin(
`;
try {
await brevoService.sendEmail({
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 minglar admin via email.");