@@ -345,41 +345,62 @@ export class EmailSender {
345345
346346 const backoffDelay = this . calculateBackoffDelay ( attempt ) ;
347347
348- this . log . warn ( 'mailer.send.retry' , {
348+ const retryLogDetails : Record < string , unknown > = {
349349 err : err . message ,
350350 to : email . to ,
351351 template : email . template ,
352352 retryAttempt : attempt ,
353353 nextAttempt : attempt + 1 ,
354354 backoffMs : Math . round ( backoffDelay ) ,
355- } ) ;
355+ } ;
356+
357+ if ( err . response ) {
358+ retryLogDetails [ 'smtpResponse' ] = err . response ;
359+ }
360+ if ( err . responseCode ) {
361+ retryLogDetails [ 'smtpResponseCode' ] = err . responseCode ;
362+ }
363+ if ( err . rejected ?. length ) {
364+ retryLogDetails [ 'rejectedRecipients' ] = err . rejected ;
365+ }
366+
367+ this . log . warn ( 'mailer.send.retry' , retryLogDetails ) ;
356368
357369 // Wait for backoff period, then retry
358370 await new Promise ( ( resolve ) => setTimeout ( resolve , backoffDelay ) ) ;
359371 return this . sendMail ( email , ++ attempt ) ;
360372 }
361373
362- // This is the final failure - log and capture to Sentry
374+ const smtpErrorDetails : Record < string , unknown > = {
375+ err : err . message ,
376+ to : email . to ,
377+ template : email . template ,
378+ isRetry,
379+ retryAttempt : attempt ,
380+ } ;
381+
382+ if ( email . cc ?. length ) {
383+ smtpErrorDetails [ 'cc' ] = email . cc ;
384+ }
385+ if ( err . response ) {
386+ smtpErrorDetails [ 'smtpResponse' ] = err . response ;
387+ }
388+ if ( err . responseCode ) {
389+ smtpErrorDetails [ 'smtpResponseCode' ] = err . responseCode ;
390+ }
391+ if ( err . rejected ?. length ) {
392+ smtpErrorDetails [ 'rejectedRecipients' ] = err . rejected ;
393+ }
394+ if ( err . accepted ?. length ) {
395+ smtpErrorDetails [ 'acceptedRecipients' ] = err . accepted ;
396+ }
363397 if ( isAppError ( err ) ) {
364- this . log . error ( 'mailer.send.error' , {
365- err : err . message ,
366- code : err . code ,
367- errno : err . errno ,
368- to : email . to ,
369- template : email . template ,
370- isRetry,
371- retryAttempt : attempt ,
372- } ) ;
373- } else {
374- this . log . error ( 'mailer.send.error' , {
375- err : err . message ,
376- to : email . to ,
377- template : email . template ,
378- isRetry,
379- retryAttempt : attempt ,
380- } ) ;
398+ smtpErrorDetails [ 'code' ] = err . code ;
399+ smtpErrorDetails [ 'errno' ] = err . errno ;
381400 }
382401
402+ this . log . error ( 'mailer.send.error' , smtpErrorDetails ) ;
403+
383404 // Only capture to Sentry on final failure
384405 Sentry . captureException ( err ) ;
385406
0 commit comments