Skip to content

: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.

feat(workflows): set up and verify a broadcast's email sender without leaving the wizard (#106686)

Daniel Marchukfd2c5fdc3b72
diff --git a/products/workflows/frontend/Broadcasts/broadcastSender.test.ts b/products/workflows/frontend/Broadcasts/broadcastSender.test.ts
new file mode 100644
index 000000000000..25e680ab5bff
--- /dev/null
+++ b/products/workflows/frontend/Broadcasts/broadcastSender.test.ts
@@ -0,0 +1,31 @@
+import type { IntegrationType } from '~/types'
+
+import { SENDERS_LOAD_FAILED_ERROR, getSenderLaunchError } from './broadcastWizardLogic'
+
+const sender = (id: number, verified: boolean): IntegrationType => ({
+ id,
+ kind: 'email',
+ display_name: `sender-${id}`,
+ icon_url: '',
+ config: { verified },
+ created_at: '2026-01-01T00:00:00Z',
+})
+
+describe('getSenderLaunchError', () => {
+ it.each([
+ ['no sender chosen yet', undefined, [sender(1, true)], false, null],
+ ['a verified sender', 1, [sender(1, true)], false, null],
+ ['an unverified sender', 1, [sender(1, false)], false, "Verify the sender's domain before sending"],
+ ['senders still loading', 1, null, true, 'Checking the email sender. Try again in a moment.'],
+ ['senders failed to load', 1, null, false, SENDERS_LOAD_FAILED_ERROR],
+ [
+ 'a sender that was deleted',
+ 7,
+ [sender(1, true)],
+ false,
+ 'The chosen email sender no longer exists. Pick another one on the content step.',
+ ],
+ ])('blocks launch for %s', (_, integrationId, integrations, integrationsLoading, expected) => {
+ expect(getSenderLaunchError(integrationId, integrations, integrationsLoading)).toBe(expected)
+ })
+})
diff --git a/products/workflows/frontend/Broadcasts/broadcastWizardLogic.ts b/products/workflows/frontend/Broadcasts/broadcastWizardLogic.ts
index 7569b9f3070a..af7c6be7618e 100644
--- a/products/workflows/frontend/Broadcasts/broadcastWizardLogic.ts
+++ b/products/workflows/frontend/Broadcasts/broadcastWizardLogic.ts
@@ -5,6 +5,7 @@ import { router } from 'kea-router'
import { lemonToast } from '@posthog/lemon-ui'
import { dayjs } from 'lib/dayjs'
+import { integrationsLogic } from 'lib/integrations/integrationsLogic'
import { humanFriendlyDuration } from 'lib/utils/durations'
import { humanFriendlyNumber } from 'lib/utils/numbers'
import { projectLogic } from 'scenes/projectLogic'
@@ -12,7 +13,7 @@ import { Scene } from 'scenes/sceneTypes'
import { teamLogic } from 'scenes/teamLogic'
import { urls } from 'scenes/urls'
-import { AnyPropertyFilter, Breadcrumb, TeamPublicType, TeamType } from '~/types'
+import { AnyPropertyFilter, Breadcrumb, IntegrationType, TeamPublicType, TeamType } from '~/types'
import {
hogFlowsBatchJobsCancelCreate,
@@ -109,6 +110,8 @@ export interface BroadcastWizardLogicProps {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface broadcastWizardLogicValues {
+ integrations: IntegrationType[] | null // integrationsLogic
+ integrationsLoading: boolean // integrationsLogic
currentProjectId: number | null // projectLogic
currentTeam: TeamPublicType | TeamType | null // teamLogic
audienceProperties: AnyPropertyFilter[]
@@ -147,6 +150,7 @@ export interface broadcastWizardLogicValues {
scheduleState: ScheduleState
scheduleSummary: string
scheduleTimezone: string | null
+ selectedSender: IntegrationType | null
sendAt: string | null
stepValidationErrors: Record<BroadcastWizardStep, string[]>
summaryStatus: BroadcastStatus
@@ -319,13 +323,16 @@ export interface broadcastWizardLogicMeta {
) => BroadcastStatus
isReadOnly: (broadcast: HogFlowApi | null) => boolean
effectiveTimezone: (scheduleTimezone: string | null, currentTeam: TeamPublicType | TeamType | null) => string
+ selectedSender: (email: BroadcastEmailValue, integrations: IntegrationType[] | null) => IntegrationType | null
stepValidationErrors: (
goalEnabled: boolean,
conversion: HogFlowConversionApi,
email: BroadcastEmailValue,
scheduleMode: BroadcastScheduleMode,
sendAt: string | null,
- recurringStartsAt: string | null
+ recurringStartsAt: string | null,
+ integrations: IntegrationType[] | null,
+ integrationsLoading: boolean
) => Record<BroadcastWizardStep, string[]>
currentStepHasErrors: (
stepValidationErrors: Record<BroadcastWizardStep, string[]>,
@@ -361,7 +368,14 @@ export const broadcastWizardLogic = kea<broadcastWizardLogicType>([
key((props) => props.id),
connect(() => ({
- values: [projectLogic, ['currentProjectId'], teamLogic, ['currentTeam']],
+ values: [
+ projectLogic,
+ ['currentProjectId'],
+ teamLogic,
+ ['currentTeam'],
+ integrationsLogic,
+ ['integrations', 'integrationsLoading'],
+ ],
})),
actions({
@@ -680,15 +694,33 @@ export const broadcastWizardLogic = kea<broadcastWizardLogicType>([
(scheduleTimezone: string | null, currentTeam: TeamPublicType | TeamType | null): string =>
scheduleTimezone ?? currentTeam?.timezone ?? dayjs.tz.guess(),
],
+ selectedSender: [
+ (s) => [s.email, s.integrations],
+ (email: BroadcastEmailValue, integrations: IntegrationType[] | null): IntegrationType | null =>
+ integrations?.find(
+ (integration) => integration.kind === 'email' && integration.id === email.from?.integrationId
+ ) ?? null,
+ ],
stepValidationErrors: [
- (s) => [s.goalEnabled, s.conversion, s.email, s.scheduleMode, s.sendAt, s.recurringStartsAt],
+ (s) => [
+ s.goalEnabled,
+ s.conversion,
+ s.email,
+ s.scheduleMode,
+ s.sendAt,
+ s.recurringStartsAt,
+ s.integrations,
+ s.integrationsLoading,
+ ],
(
goalEnabled: boolean,
conversion: HogFlowConversionApi,
email: BroadcastEmailValue,
scheduleMode: BroadcastScheduleMode,
sendAt: string | null,
- recurringStartsAt: string | null
+ recurringStartsAt: string | null,
+ integrations: IntegrationType[] | null,
+ integrationsLoading: boolean
): Record<BroadcastWizardStep, string[]> => {
const errors: Record<BroadcastWizardStep, string[]> = {
recipients: [],
@@ -728,6 +760,10 @@ export const broadcastWizardLogic = kea<broadcastWizardLogicType>([
}
errors.review = [...errors.recipients, ...errors.goal, ...errors.content, ...errors.schedule]
+ const senderError = getSenderLaunchError(email.from?.integrationId, integrations, integrationsLoading)
+ if (senderError) {
+ errors.review.push(senderError)
+ }
return errors
},
@@ -1078,6 +1114,30 @@ export const broadcastWizardLogic = kea<broadcastWizardLogicType>([
}),
])
+export const SENDERS_LOAD_FAILED_ERROR = "Couldn't load your email senders. Reload them to launch."
+
+/**
+ * Why the chosen sender can't send yet, if it can't. A draft can be written with any sender, but a
+ * launch whose sender is unverified, deleted, or not yet known would fail every email it sends.
+ */
+export function getSenderLaunchError(
+ integrationId: number | null | undefined,
+ integrations: IntegrationType[] | null,
+ integrationsLoading: boolean
+): string | null {
+ if (!integrationId) {
+ return null
+ }
+ if (!integrations) {
+ return integrationsLoading ? 'Checking the email sender. Try again in a moment.' : SENDERS_LOAD_FAILED_ERROR
+ }
+ const sender = integrations.find((integration) => integration.kind === 'email' && integration.id === integrationId)
+ if (!sender) {
+ return 'The chosen email sender no longer exists. Pick another one on the content step.'
+ }
+ return sender.config?.verified === true ? null : "Verify the sender's domain before sending"
+}
+
// Serializes the wizard state into the HogFlow the broadcast is stored as: a batch trigger
// (the audience), one email action, and an exit node.
export function buildBroadcastPayload(values: {
diff --git a/products/workflows/frontend/Broadcasts/steps/BroadcastContentStep.tsx b/products/workflows/frontend/Broadcasts/steps/BroadcastContentStep.tsx
index ddf0b05818ce..a9c457c40cac 100644
--- a/products/workflows/frontend/Broadcasts/steps/BroadcastContentStep.tsx
+++ b/products/workflows/frontend/Broadcasts/steps/BroadcastContentStep.tsx
@@ -1,18 +1,38 @@
import { useActions, useValues } from 'kea'
import { useState } from 'react'
-import { LemonButton } from '@posthog/lemon-ui'
+import { LemonBanner, LemonButton } from '@posthog/lemon-ui'
+import { integrationsLogic } from 'lib/integrations/integrationsLogic'
import { EmailTemplater, TemplatePickerModal } from 'scenes/hog-functions/email-templater/EmailTemplater'
import type { EmailFieldErrors, EmailTemplate } from 'scenes/hog-functions/email-templater/types'
+import { IntegrationType } from '~/types'
+
+import { EmailSetupModal } from '../../Channels/EmailSetup/EmailSetupModal'
import { buildSampleGlobals } from '../../Workflows/hogflows/steps/components/HogFlowFunctionConfiguration'
import { BroadcastEmailValue, DEFAULT_BROADCAST_EMAIL, broadcastWizardLogic } from '../broadcastWizardLogic'
export function BroadcastContentStep(): JSX.Element {
- const { email, stepValidationErrors } = useValues(broadcastWizardLogic)
+ const { email, stepValidationErrors, selectedSender } = useValues(broadcastWizardLogic)
const { setEmail } = useActions(broadcastWizardLogic)
+ const { integrations, integrationsLoading } = useValues(integrationsLogic)
+ const { loadIntegrations } = useActions(integrationsLogic)
const [templatePickerOpen, setTemplatePickerOpen] = useState(false)
+ // null: closed. 'new': set up a sender. An integration: finish verifying that one.
+ const [senderSetup, setSenderSetup] = useState<'new' | IntegrationType | null>(null)
+
+ const hasSenders = !!integrations?.some((integration) => integration.kind === 'email')
+ const senderUnverified = !!selectedSender && selectedSender.config?.verified !== true
+
+ // Closing the modal after Continue also keeps the sender it created or verified.
+ const closeSenderSetup = (integrationId?: number): void => {
+ setSenderSetup(null)
+ if (integrationId) {
+ loadIntegrations()
+ setEmail({ ...email, from: { ...email.from, integrationId } })
+ }
+ }
const errors = stepValidationErrors.content
const fieldErrors: EmailFieldErrors = {
@@ -38,6 +58,38 @@ export function BroadcastContentStep(): JSX.Element {
</LemonButton>
</div>
<TemplatePickerModal isOpen={templatePickerOpen} onClose={() => setTemplatePickerOpen(false)} />
+ {!integrationsLoading && integrations && !hasSenders ? (
+ <LemonBanner
+ type="info"
+ action={{
+ children: 'Set up email sender',
+ onClick: () => setSenderSetup('new'),
+ 'data-attr': 'broadcast-setup-sender',
+ }}
+ >
+ Broadcasts send from your own domain. Set up a sender, then verify the domain with a few DNS
+ records.
+ </LemonBanner>
+ ) : senderUnverified ? (
+ <LemonBanner
+ type="warning"
+ action={{
+ children: 'Verify domain',
+ onClick: () => setSenderSetup(selectedSender),
+ 'data-attr': 'broadcast-verify-sender',
+ }}
+ >
+ {selectedSender?.display_name} is not verified yet. You can keep writing, but the broadcast can't
+ send until its domain is verified.
+ </LemonBanner>
+ ) : null}
+ {senderSetup ? (
+ <EmailSetupModal
+ integration={senderSetup === 'new' ? undefined : senderSetup}
+ onClose={closeSenderSetup}
+ onComplete={closeSenderSetup}
+ />
+ ) : null}
<EmailTemplater
type="native_email"
templating="liquid"
diff --git a/products/workflows/frontend/Broadcasts/steps/BroadcastReviewStep.tsx b/products/workflows/frontend/Broadcasts/steps/BroadcastReviewStep.tsx
index baee495135e9..cc1824e01808 100644
--- a/products/workflows/frontend/Broadcasts/steps/BroadcastReviewStep.tsx
+++ b/products/workflows/frontend/Broadcasts/steps/BroadcastReviewStep.tsx
@@ -1,12 +1,13 @@
-import { useValues } from 'kea'
+import { useActions, useValues } from 'kea'
-import { Spinner } from '@posthog/lemon-ui'
+import { LemonButton, Spinner } from '@posthog/lemon-ui'
import PropertyFiltersDisplay from 'lib/components/PropertyFilters/components/PropertyFiltersDisplay'
+import { integrationsLogic } from 'lib/integrations/integrationsLogic'
import { humanFriendlyNumber } from 'lib/utils/numbers'
import { BroadcastEmailPreview } from '../BroadcastEmailPreview'
-import { broadcastWizardLogic } from '../broadcastWizardLogic'
+import { SENDERS_LOAD_FAILED_ERROR, broadcastWizardLogic } from '../broadcastWizardLogic'
function ReviewRow({ label, children }: { label: string; children: React.ReactNode }): JSX.Element {
return (
@@ -29,6 +30,8 @@ export function BroadcastReviewStep(): JSX.Element {
rateLimitedSendDuration,
stepValidationErrors,
} = useValues(broadcastWizardLogic)
+ const { integrationsLoading } = useValues(integrationsLogic)
+ const { loadIntegrations } = useActions(integrationsLogic)
const goalEventNames: string[] = goalEnabled
? (conversion.events?.[0]?.filters?.events ?? []).map(
@@ -95,6 +98,19 @@ export function BroadcastReviewStep(): JSX.Element {
{error}
</div>
))}
+ {stepValidationErrors.review.includes(SENDERS_LOAD_FAILED_ERROR) && (
+ <div>
+ <LemonButton
+ type="secondary"
+ size="small"
+ onClick={() => loadIntegrations()}
+ loading={integrationsLoading}
+ data-attr="broadcast-reload-senders"
+ >
+ Reload email senders
+ </LemonButton>
+ </div>
+ )}
</div>
)}
</div>
diff --git a/products/workflows/frontend/Channels/EmailSetup/EmailSetupModal.tsx b/products/workflows/frontend/Channels/EmailSetup/EmailSetupModal.tsx
index a6bfa01495f5..b0f59a820fb2 100644
--- a/products/workflows/frontend/Channels/EmailSetup/EmailSetupModal.tsx
+++ b/products/workflows/frontend/Channels/EmailSetup/EmailSetupModal.tsx
@@ -29,7 +29,7 @@ export const EmailSetupModal = (props: EmailSetupModalLogicProps): JSX.Element =
return (
<>
- <LemonModal title="Configure email sender" width="auto" onClose={props.onClose}>
+ <LemonModal title="Configure email sender" width="auto" onClose={() => props.onClose(savedIntegration?.id)}>
<Form logic={emailSetupModalLogic} props={props} formKey="emailSender">
<div className="space-y-4">
<FlaggedFeature flag="messaging-ses">
diff --git a/products/workflows/frontend/Channels/EmailSetup/emailSetupModalLogic.ts b/products/workflows/frontend/Channels/EmailSetup/emailSetupModalLogic.ts
index b0e11385882e..8d8a70dda1ab 100644
--- a/products/workflows/frontend/Channels/EmailSetup/emailSetupModalLogic.ts
+++ b/products/workflows/frontend/Channels/EmailSetup/emailSetupModalLogic.ts
@@ -14,7 +14,7 @@ import type { EmailSenderDomainStatus } from '../../../../../frontend/src/types'
export interface EmailSetupModalLogicProps {
integration?: IntegrationType | null
onComplete: (integrationId?: number) => void
- onClose: () => void
+ onClose: (savedIntegrationId?: number) => void
}
export interface ApiDnsRecord {