@@ -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
485487const 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
494497module . 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 } : { } )
0 commit comments