Просмотр исходного кода

[web] support email sender customization for email notifications (#33035)

GitOrigin-RevId: 9aa298c233c1f314ef3bdb381c20692bd0d4e212
Kristina 5 месяцев назад
Родитель
Сommit
b556fd40b5

+ 1 - 1
services/web/app/src/Features/Email/EmailSender.mjs

@@ -97,7 +97,7 @@ async function sendEmail(options, emailType) {
     metrics.inc('email')
     metrics.inc('email')
     const sendMailOptions = {
     const sendMailOptions = {
       to: options.to,
       to: options.to,
-      from: EMAIL_SETTINGS.fromAddress || '',
+      from: options.from || EMAIL_SETTINGS.fromAddress || '',
       subject: options.subject,
       subject: options.subject,
       html: options.html,
       html: options.html,
       text: options.text,
       text: options.text,

+ 8 - 0
services/web/test/unit/src/Email/EmailSender.test.mjs

@@ -99,6 +99,14 @@ describe('EmailSender', function () {
       })
       })
     })
     })
 
 
+    it('should use opts.from as override for settings fromAddress when provided', async function (ctx) {
+      ctx.opts.from = 'no-reply@example.com'
+      await ctx.EmailSender.promises.sendEmail(ctx.opts)
+      expect(ctx.sesClient.sendMail).to.have.been.calledWithMatch({
+        from: 'no-reply@example.com',
+      })
+    })
+
     it('should not send an email when the rate limiter says no', async function (ctx) {
     it('should not send an email when the rate limiter says no', async function (ctx) {
       ctx.opts.sendingUser_id = '12321312321'
       ctx.opts.sendingUser_id = '12321312321'
       ctx.rateLimiter.consume.rejects({ remainingPoints: 0 })
       ctx.rateLimiter.consume.rejects({ remainingPoints: 0 })