From 5469e76852b9e799b564d2438b5e2bda05efdd7b Mon Sep 17 00:00:00 2001 From: Sag Date: Tue, 23 Jan 2024 16:22:40 +0100 Subject: [PATCH] Fixed reply-to address to stay the same after dmarc changes (#19542) fixes PROD-102 - after dmarc changes, replies from members should keep going to any previously set reply-to email address by the publisher --- .../services/q-email-addresses.test.js | 8 ++++---- ghost/email-addresses/src/EmailAddressService.ts | 1 + ghost/email-service/lib/EmailRenderer.js | 15 ++++++--------- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/ghost/core/test/integration/services/q-email-addresses.test.js b/ghost/core/test/integration/services/q-email-addresses.test.js index aa25f62f88..01ef8446a7 100644 --- a/ghost/core/test/integration/services/q-email-addresses.test.js +++ b/ghost/core/test/integration/services/q-email-addresses.test.js @@ -262,14 +262,14 @@ describe('Email addresses', function () { assertFromAddress('"Default Address" ', 'support@address.com'); }); - it('[NEWSLETTER] Does not allow to send a newsletter from any configured email address, instead uses mail.from', async function () { + it('[NEWSLETTER] Does not allow to send a newsletter from any email address (instead uses mail.from), but allows reply-to to be set', async function () { await configureNewsletter({ sender_email: 'anything@possible.com', sender_name: 'Anything Possible', sender_reply_to: 'newsletter' }); await sendNewsletter(); - await assertFromAddressNewsletter('"Anything Possible" '); + await assertFromAddressNewsletter('"Anything Possible" ', '"Anything Possible" '); }); it('[NEWSLETTER] Does allow to send a newsletter from a custom sending domain', async function () { @@ -358,14 +358,14 @@ describe('Email addresses', function () { assertFromAddress('"Example Site" ', 'hello@acme.com'); }); - it('[NEWSLETTER] Does not allow to send a newsletter from any configured email address, instead uses mail.from', async function () { + it('[NEWSLETTER] Does not allow to send a newsletter from any email address (instead uses mail.from), but allow reply-to to be set', async function () { await configureNewsletter({ sender_email: 'anything@possible.com', sender_name: 'Anything Possible', sender_reply_to: 'newsletter' }); await sendNewsletter(); - await assertFromAddressNewsletter('"Anything Possible" '); + await assertFromAddressNewsletter('"Anything Possible" ', '"Anything Possible" '); }); it('[NEWSLETTER] Does allow to set the replyTo address to any address', async function () { diff --git a/ghost/email-addresses/src/EmailAddressService.ts b/ghost/email-addresses/src/EmailAddressService.ts index f25fbd2f85..0d0d2d9259 100644 --- a/ghost/email-addresses/src/EmailAddressService.ts +++ b/ghost/email-addresses/src/EmailAddressService.ts @@ -131,6 +131,7 @@ export class EmailAddressService { from: address.from }; } + return address; } diff --git a/ghost/email-service/lib/EmailRenderer.js b/ghost/email-service/lib/EmailRenderer.js index 93ba53bcb4..33ea2ded19 100644 --- a/ghost/email-service/lib/EmailRenderer.js +++ b/ghost/email-service/lib/EmailRenderer.js @@ -212,22 +212,19 @@ class EmailRenderer { * @returns {string|null} */ getReplyToAddress(post, newsletter) { - if (newsletter.get('sender_reply_to') === 'support') { + const replyToAddress = newsletter.get('sender_reply_to'); + + if (replyToAddress === 'support') { return this.#settingsHelpers.getMembersSupportAddress(); } - if (newsletter.get('sender_reply_to') === 'newsletter') { - if (this.#emailAddressService.managedEmailEnabled) { - // Don't duplicate the same replyTo addres if it already in the FROM address - return null; - } + + if (replyToAddress === 'newsletter' && !this.#emailAddressService.managedEmailEnabled) { return this.getFromAddress(post, newsletter); } const addresses = this.#emailAddressService.getAddress({ from: this.#getRawFromAddress(post, newsletter), - replyTo: { - address: newsletter.get('sender_reply_to') - } + replyTo: replyToAddress === 'newsletter' ? undefined : {address: replyToAddress} }); if (addresses.replyTo) {