:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(workflows): tolerate unusable email sender overrides (#84891)
Daniel Marchuk53875c3e4358
diff --git a/nodejs/src/cdp/services/messaging/email.service.test.ts b/nodejs/src/cdp/services/messaging/email.service.test.tsindex a3ef867c2c7c..c97ee0140644 100644--- a/nodejs/src/cdp/services/messaging/email.service.test.ts+++ b/nodejs/src/cdp/services/messaging/email.service.test.ts@@ -328,13 +328,18 @@ describe('EmailService', () => {['a list of addresses', '[email protected], [email protected]'],['an RFC-822 formatted address', '"Name" <[email protected]>'],['a value that is not an email address', 'not-an-email'],- ])('rejects %s without calling SES', async (_desc, email) => {+ ])('discards %s and sends from the integration sender', async (_desc, email) => {invocation.queueParameters = createEmailParams({from: { integrationId: 1, email },})const result = await service.executeSendEmail(invocation)- expect(result.error).toContain(`"${email}"`)- expect(sendEmailSpy).not.toHaveBeenCalled()+ // Failing the send would break every step still carrying the placeholder address+ // an old sender picker wrote, so an unusable override degrades to the integration's+ // own sender. The unverified address must never reach the provider either way.+ expect(result.error).toBeUndefined()+ const sentCommand = sendEmailSpy.mock.calls[0][0] as { input: any }+ expect(sentCommand.input.FromEmailAddress).toBe('"Test User" <[email protected]>')+ expect(result.logs.some((log) => log.level === 'warn' && log.message.includes(email))).toBe(true)})})describe('email sending', () => {diff --git a/nodejs/src/cdp/services/messaging/email.service.ts b/nodejs/src/cdp/services/messaging/email.service.tsindex edbe778c480d..8ca7d58d494b 100644--- a/nodejs/src/cdp/services/messaging/email.service.ts+++ b/nodejs/src/cdp/services/messaging/email.service.ts@@ -230,7 +230,7 @@ export class EmailService {)}- const from = this.resolveFromSender(integration, params.from)+ const from = this.resolveFromSender(integration, params.from, addLog)// Single choke point for the suppression check — every send path lands here regardless// of whether the invocation came from a workflow action or an email destination hog@@ -480,7 +480,8 @@ export class EmailService {private resolveFromSender(integration: IntegrationType,- from: CyclotronInvocationQueueParametersEmailType['from']+ from: CyclotronInvocationQueueParametersEmailType['from'],+ addLog: ReturnType<typeof createAddLogFunction>): { email: string; name: string } {if (!integration.config.verified) {throw new Error('The selected email integration domain is not verified')@@ -495,25 +496,34 @@ export class EmailService {const overrideName = from.name ? sanitizeFromName(from.name) : ''return {- email: this.resolveFromEmailAddress(integration, from.email?.trim()),+ email: this.resolveFromEmailAddress(integration, from.email?.trim(), addLog),name: overrideName || integration.config.name,}}- private resolveFromEmailAddress(integration: IntegrationType, overrideEmail: string | undefined): string {+ // An unusable override degrades to the integration's own sender rather than failing the send.+ // Steps authored before mid-2026 carry a placeholder address written by an old sender picker,+ // so throwing here fails sends whose author never typed an address at all.+ private resolveFromEmailAddress(+ integration: IntegrationType,+ overrideEmail: string | undefined,+ addLog: ReturnType<typeof createAddLogFunction>+ ): string {if (!overrideEmail) {return integration.config.email}if (!FROM_OVERRIDE_EMAIL_REGEX.test(overrideEmail)) {- throw new Error(- `The custom sender address "${overrideEmail}" is not a valid email address. Fix the From address in the workflow's email step so it resolves to a single valid address.`+ addLog(+ 'warn',+ `Ignoring the custom sender address "${overrideEmail}": it is not a valid email address. Sending from ${integration.config.email} instead. Fix the From address in the workflow's email step so it resolves to a single valid address.`)+ return integration.config.email}// Verification is domain-level (the DNS records cover the whole domain), so any address// on the integration's domain is exactly as verified as the integration's own address.- // Anything off-domain must fail: allowing it would let a workflow send as a domain the+ // Anything off-domain is discarded: honoring it would let a workflow send as a domain the// team never proved ownership of.const integrationDomain: string = (integration.config.domain ??@@ -522,9 +532,11 @@ export class EmailService {).toLowerCase()const overrideDomain = overrideEmail.split('@')[1].toLowerCase()if (!integrationDomain || overrideDomain !== integrationDomain) {- throw new Error(- `The custom sender address "${overrideEmail}" is not on the verified domain "${integrationDomain}" of the selected sender. Use an address on that domain, or select a different sender in the workflow's email step.`+ addLog(+ 'warn',+ `Ignoring the custom sender address "${overrideEmail}": it is not on the verified domain "${integrationDomain}" of the selected sender. Sending from ${integration.config.email} instead. Use an address on that domain, or select a different sender in the workflow's email step.`)+ return integration.config.email}return overrideEmail