Skip to content

Commit fc5fce8

Browse files
committed
feat(mail): add replyTo support to sendMail and sendBatchMail
1 parent 282e8d2 commit fc5fce8

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

‎apps/public-api/src/controllers/mail.controller.js‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ module.exports.sendMail = async (req, res, next) => {
137137

138138
const {
139139
to,
140+
replyTo,
140141
subject,
141142
html,
142143
text,
@@ -295,6 +296,7 @@ module.exports.sendMail = async (req, res, next) => {
295296
to,
296297
subject: resolvedSubject,
297298
};
299+
if (replyTo) payload.reply_to = replyTo;
298300
if (typeof resolvedHtml === "string" && resolvedHtml.trim()) payload.html = resolvedHtml;
299301
if (typeof resolvedText === "string" && resolvedText.trim()) payload.text = resolvedText;
300302

@@ -484,12 +486,13 @@ module.exports.handleResendWebhook = async (req, res, next) => {
484486
// POST /api/mail/send-batch
485487
const sendBatchSchema = z.array(
486488
z.object({
487-
to: z.union([z.string(), z.array(z.string())]),
488-
subject: z.string().min(1, "Subject is required"),
489+
to: z.union([z.string().email(), z.array(z.string().email()).nonempty()]),
490+
replyTo: z.union([z.string().email(), z.array(z.string().email())]).optional(),
491+
subject: z.string().min(1),
489492
html: z.string().optional(),
490493
text: z.string().optional()
491-
})
492-
).min(1).max(100);
494+
}).refine(data => data.html || data.text, { message: "Provide html or text" })
495+
).min(1, "Batch cannot be empty").max(100, "Max 100 emails per batch");
493496

494497
module.exports.sendBatchMail = async (req, res, next) => {
495498
const reservedKeys = [];
@@ -515,6 +518,7 @@ module.exports.sendBatchMail = async (req, res, next) => {
515518
const resendPayloads = batch.map(item => ({
516519
from: fromAddress,
517520
to: Array.isArray(item.to) ? item.to : [item.to],
521+
...(item.replyTo ? { reply_to: Array.isArray(item.replyTo) ? item.replyTo : [item.replyTo] } : {}),
518522
subject: item.subject,
519523
...(item.html ? { html: item.html } : {}),
520524
...(item.text ? { text: item.text } : {})

‎packages/common/src/utils/input.validation.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,10 @@ module.exports.sendMailSchema = z
654654
z.string().email("Invalid recipient email format"),
655655
z.array(z.string().email("Invalid recipient email format")).nonempty("Recipient list cannot be empty")
656656
]),
657+
replyTo: z.union([
658+
z.string().email("Invalid replyTo email format"),
659+
z.array(z.string().email("Invalid replyTo email format"))
660+
]).optional(),
657661

658662
// Direct-send fields (backward compatible)
659663
subject: z.preprocess(

0 commit comments

Comments
 (0)