From f9fc4f928528d65c767371caaf75645bd57cd895 Mon Sep 17 00:00:00 2001 From: Mikkel Svartveit Date: Fri, 13 Nov 2026 21:50:02 +0100 Subject: [PATCH 1/2] fix(web): allow a Reply-To email on any domain The Reply-To field reused the From field's input, which only offers verified domains. Only the From address needs a verified domain, and the API already accepts any Reply-To address, so use a plain email input. Co-Authored-By: Claude Opus 5.5 --- apps/web/src/components/EmailSettings.tsx | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/apps/web/src/components/EmailSettings.tsx b/apps/web/src/components/EmailSettings.tsx index 78addb06d..b6be96f39 100644 --- a/apps/web/src/components/EmailSettings.tsx +++ b/apps/web/src/components/EmailSettings.tsx @@ -26,11 +26,8 @@ export function EmailSettings({ replyToPlaceholder, layout = 'grid', }: EmailSettingsProps) { - // Use from email's local part as the reply-to placeholder if not provided - // Extract local part (before @) since the domain is shown in a dropdown - // Fall back to fromPlaceholder when from is empty (since reply-to defaults to from) - const fromLocalPart = from.includes('@') ? from.split('@')[0] : from; - const effectiveReplyToPlaceholder = replyToPlaceholder || fromLocalPart || fromPlaceholder; + // Reply-to defaults to the from address, so show it as the placeholder + const effectiveReplyToPlaceholder = replyToPlaceholder || from || 'Same as From email'; const GridWrapper = layout === 'grid' ? 'div' : 'div'; const gridClassName = layout === 'grid' ? 'grid gap-4 md:grid-cols-2' : 'space-y-4'; @@ -65,13 +62,17 @@ export function EmailSettings({
- Reply-To email + onReplyToChange(e.target.value)} placeholder={effectiveReplyToPlaceholder} /> +

+ Where replies are sent. Can be on any domain. Defaults to the From email if not set. +

From 57d20725abc7c09a6b1e56516d06073d67a79bc3 Mon Sep 17 00:00:00 2001 From: Mikkel Svartveit Date: Fri, 13 Nov 2026 22:14:29 +0100 Subject: [PATCH 2/2] fix(api): reject an invalid Reply-To on templates and campaigns The dashboard now takes Reply-To as free text, and its floating save bar skips the browser's form validation, so check the address on the server. Template create and update and campaign update now return 400 for a Reply-To that is not an email address. Empty values are still allowed. Campaign create already validates it through CampaignSchemas.create. Co-Authored-By: Claude Opus 5.5 --- apps/api/src/controllers/Campaigns.ts | 3 ++- apps/api/src/controllers/Templates.ts | 4 ++- .../__tests__/templateValidation.test.ts | 27 ++++++++++++++++++- apps/api/src/utils/templateValidation.ts | 20 ++++++++++++++ 4 files changed, 51 insertions(+), 3 deletions(-) diff --git a/apps/api/src/controllers/Campaigns.ts b/apps/api/src/controllers/Campaigns.ts index b8f1af9d2..cb5c171db 100644 --- a/apps/api/src/controllers/Campaigns.ts +++ b/apps/api/src/controllers/Campaigns.ts @@ -10,7 +10,7 @@ import {CampaignService} from '../services/CampaignService.js'; import {DomainService} from '../services/DomainService.js'; import {CatchAsync} from '../utils/asyncHandler.js'; import {parseListSort} from '../utils/listSort.js'; -import {assertValidTemplateSyntax} from '../utils/templateValidation.js'; +import {assertValidReplyTo, assertValidTemplateSyntax} from '../utils/templateValidation.js'; @Controller('campaigns') export class Campaigns { @@ -180,6 +180,7 @@ export class Campaigns { if (from) { await DomainService.verifyEmailDomain(from, auth.projectId); } + assertValidReplyTo(replyTo); const campaign = await CampaignService.update(auth.projectId, id!, { name, diff --git a/apps/api/src/controllers/Templates.ts b/apps/api/src/controllers/Templates.ts index da2c989c8..ac07292bb 100644 --- a/apps/api/src/controllers/Templates.ts +++ b/apps/api/src/controllers/Templates.ts @@ -7,7 +7,7 @@ import {DomainService} from '../services/DomainService.js'; import {TemplateService} from '../services/TemplateService.js'; import {CatchAsync} from '../utils/asyncHandler.js'; import {parseListSort} from '../utils/listSort.js'; -import {assertValidTemplateSyntax} from '../utils/templateValidation.js'; +import {assertValidReplyTo, assertValidTemplateSyntax} from '../utils/templateValidation.js'; @Controller('templates') export class Templates { @@ -89,6 +89,7 @@ export class Templates { // Verify domain ownership and verification await DomainService.verifyEmailDomain(from, auth.projectId!); + assertValidReplyTo(replyTo); const template = await TemplateService.create(auth.projectId!, { name, @@ -126,6 +127,7 @@ export class Templates { if (from) { await DomainService.verifyEmailDomain(from, auth.projectId!); } + assertValidReplyTo(replyTo); const template = await TemplateService.update(auth.projectId!, templateId, { name, diff --git a/apps/api/src/utils/__tests__/templateValidation.test.ts b/apps/api/src/utils/__tests__/templateValidation.test.ts index b20336405..4997d4503 100644 --- a/apps/api/src/utils/__tests__/templateValidation.test.ts +++ b/apps/api/src/utils/__tests__/templateValidation.test.ts @@ -1,7 +1,7 @@ import {describe, expect, it} from 'vitest'; import {HttpException} from '../../exceptions/index.js'; -import {assertValidTemplateSyntax} from '../templateValidation.js'; +import {assertValidReplyTo, assertValidTemplateSyntax} from '../templateValidation.js'; /** * Rendering is intentionally forgiving — a broken template still sends, falling back to @@ -62,3 +62,28 @@ describe('assertValidTemplateSyntax', () => { expect(() => assertValidTemplateSyntax({subject: '{% if %}', body: 'fine'})).toThrow(/subject/); }); }); + +/** + * Reply-To is free text in the dashboard because it may be on any domain, so this is + * what keeps a typo out of every email the template or campaign sends. + */ +describe('assertValidReplyTo', () => { + it('accepts an address on any domain', () => { + expect(() => assertValidReplyTo('support@other-domain.com')).not.toThrow(); + }); + + it('ignores a Reply-To that is absent or empty', () => { + expect(() => assertValidReplyTo(undefined)).not.toThrow(); + expect(() => assertValidReplyTo(null)).not.toThrow(); + expect(() => assertValidReplyTo('')).not.toThrow(); + }); + + it('rejects a value that is not an email address', () => { + expect(() => assertValidReplyTo('not-an-email')).toThrow(HttpException); + expect(() => assertValidReplyTo('support@')).toThrow('Reply-To must be a valid email address'); + }); + + it('rejects a non-string value', () => { + expect(() => assertValidReplyTo(42)).toThrow(HttpException); + }); +}); diff --git a/apps/api/src/utils/templateValidation.ts b/apps/api/src/utils/templateValidation.ts index 578cae410..78a9c59be 100644 --- a/apps/api/src/utils/templateValidation.ts +++ b/apps/api/src/utils/templateValidation.ts @@ -1,4 +1,5 @@ import {validateTemplate} from '@plunk/shared'; +import {z} from 'zod'; import {ErrorCode, HttpException} from '../exceptions/index.js'; @@ -34,3 +35,22 @@ export function assertValidTemplateSyntax(fields: Record): void } } } + +/** + * Reject a Reply-To that is not an email address. + * + * Unlike `from`, Reply-To may be on any domain, so the dashboard takes it as free + * text. Checking it here keeps a typo out of every email the template or campaign sends. + * Absent or empty values are allowed: they fall back to the from address. + */ +export function assertValidReplyTo(replyTo: unknown): void { + if (replyTo === undefined || replyTo === null || replyTo === '') { + return; + } + + if (!z.string().email().safeParse(replyTo).success) { + throw new HttpException(400, 'Reply-To must be a valid email address', ErrorCode.VALIDATION_ERROR, { + field: 'replyTo', + }); + } +}