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): add a default reply-to address to email senders (#115898)

Meikel Ratzb99095c78f38
diff --git a/posthog/api/integration.py b/posthog/api/integration.py
index 67af063ef3dc..ca28809d8f77 100644
--- a/posthog/api/integration.py
+++ b/posthog/api/integration.py
@@ -308,6 +308,11 @@ class NativeEmailIntegrationSerializer(serializers.Serializer):
name = serializers.CharField()
provider = serializers.ChoiceField(choices=["ses", "maildev"] if settings.DEBUG else ["ses"])
mail_from_subdomain = serializers.CharField(required=False, allow_blank=True)
+ reply_to = serializers.EmailField(
+ required=False,
+ allow_blank=True,
+ help_text="Reply-to address for emails from this sender when the email step sets none. Blank clears it.",
+ )
def validate_email(self, value: str) -> str:
return value.lower()
diff --git a/posthog/api/test/test_integration.py b/posthog/api/test/test_integration.py
index 8d398ac9be3e..06235a0adb1b 100644
--- a/posthog/api/test/test_integration.py
+++ b/posthog/api/test/test_integration.py
@@ -628,12 +628,21 @@ class TestEmailIntegration:
self.organization = Organization.objects.create(name="Test Org")
self.team = Team.objects.create(organization=self.organization, name="Test Team")
+ @patch("posthog.models.integration.email.reload_integrations_on_workers")
+ @patch("products.workflows.backend.facade.api.update_ses_mail_from_subdomain")
@patch("products.workflows.backend.facade.api.verify_ses_email_domain")
@patch("products.workflows.backend.facade.api.create_ses_email_domain")
- def test_integration_from_domain(self, mock_create_email_domain, mock_verify_email_domain):
+ def test_integration_from_domain(
+ self, mock_create_email_domain, mock_verify_email_domain, _mock_update, mock_reload
+ ):
integration = EmailIntegration.create_native_integration(
- {**self.valid_config, "mail_from_subdomain": "youmustnothavelikedmyemail", "provider": "ses"},
+ {
+ **self.valid_config,
+ "mail_from_subdomain": "youmustnothavelikedmyemail",
+ "provider": "ses",
+ "reply_to": "[email protected]",
+ },
team_id=self.team.id,
organization_id=self.organization.id,
created_by=self.user,
@@ -646,6 +655,7 @@ class TestEmailIntegration:
"name": self.valid_config["name"],
"domain": "posthog.com",
"mail_from_subdomain": "youmustnothavelikedmyemail",
+ "reply_to": "[email protected]",
"verified": False,
"provider": "ses",
}
@@ -659,6 +669,13 @@ class TestEmailIntegration:
org_team_ids=[self.team.id],
)
+ EmailIntegration(integration).update_native_integration({"name": "Renamed"}, self.team.id)
+ assert integration.config["reply_to"] == "[email protected]"
+
+ EmailIntegration(integration).update_native_integration({"reply_to": ""}, self.team.id)
+ assert integration.config["reply_to"] == ""
+ mock_reload.assert_called_with(self.team.id, [integration.id])
+
@patch("products.workflows.backend.facade.api.verify_ses_email_domain")
@patch("products.workflows.backend.facade.api.create_ses_email_domain")
def test_email_verify_returns_ses_result(self, mock_create_email_domain, mock_verify_email_domain):
@@ -713,6 +730,7 @@ class TestEmailIntegration:
"name": self.valid_config["name"],
"domain": "posthog.com",
"mail_from_subdomain": "feedback",
+ "reply_to": "",
"verified": False,
"provider": "ses",
}
@@ -749,6 +767,7 @@ class TestEmailIntegration:
"name": self.valid_config["name"],
"domain": "posthog.com",
"mail_from_subdomain": "feedback",
+ "reply_to": "",
"verified": True,
"provider": "ses",
}
diff --git a/posthog/models/integration/email.py b/posthog/models/integration/email.py
index 89105deedf23..2dc30b43d6cc 100644
--- a/posthog/models/integration/email.py
+++ b/posthog/models/integration/email.py
@@ -77,6 +77,7 @@ class EmailIntegration:
"email": email_address,
"domain": domain,
"mail_from_subdomain": mail_from_subdomain,
+ "reply_to": config.get("reply_to", ""),
"name": name,
"provider": provider,
"verified": True if provider == "maildev" else False,
@@ -94,7 +95,7 @@ class EmailIntegration:
def update_native_integration(self, config: dict, team_id: int) -> model.Integration:
provider = self.integration.config.get("provider")
domain = self.integration.config.get("domain")
- # Only name and mail_from_subdomain can be updated
+ # Only name, mail_from_subdomain and reply_to can be updated
name: str = config.get("name", self.integration.config.get("name"))
mail_from_subdomain: str = config.get(
"mail_from_subdomain", self.integration.config.get("mail_from_subdomain", "feedback")
@@ -116,9 +117,11 @@ class EmailIntegration:
{
"name": name,
"mail_from_subdomain": mail_from_subdomain,
+ "reply_to": config.get("reply_to", self.integration.config.get("reply_to", "")),
}
)
self.integration.save()
+ reload_integrations_on_workers(self.integration.team_id, [self.integration.id])
return self.integration
diff --git a/products/workflows/frontend/Channels/EmailSetup/EmailSetupModal.tsx b/products/workflows/frontend/Channels/EmailSetup/EmailSetupModal.tsx
index b0f59a820fb2..2a59e7c75665 100644
--- a/products/workflows/frontend/Channels/EmailSetup/EmailSetupModal.tsx
+++ b/products/workflows/frontend/Channels/EmailSetup/EmailSetupModal.tsx
@@ -80,6 +80,20 @@ export const EmailSetupModal = (props: EmailSetupModalLogicProps): JSX.Element =
}
/>
</LemonField>
+ <LemonField
+ name="reply_to"
+ label="Default reply-to address"
+ help="Replies go here when an email step has no reply-to address of its own. Leave empty to send replies to the sender address."
+ showOptional
+ >
+ <LemonInput
+ type="text"
+ placeholder="[email protected]"
+ disabledReason={
+ verificationLoading || isEmailSenderSubmitting ? 'Creating sender...' : undefined
+ }
+ />
+ </LemonField>
{!savedIntegration && (
<div className="flex justify-end">
<LemonButton
@@ -222,10 +236,8 @@ export const EmailSetupModal = (props: EmailSetupModalLogicProps): JSX.Element =
</LemonButton>
<LemonButton
type="primary"
- onClick={async () => {
- await submitEmailSender()
- props.onComplete(savedIntegration?.id)
- }}
+ onClick={submitEmailSender}
+ loading={isEmailSenderSubmitting}
tooltip="You will not be able to send emails until you verify the DNS records"
>
{isDomainVerified ? 'Save' : 'Save & finish later'}
diff --git a/products/workflows/frontend/Channels/EmailSetup/emailSetupModalLogic.ts b/products/workflows/frontend/Channels/EmailSetup/emailSetupModalLogic.ts
index c56491edfb95..c68a968b0d22 100644
--- a/products/workflows/frontend/Channels/EmailSetup/emailSetupModalLogic.ts
+++ b/products/workflows/frontend/Channels/EmailSetup/emailSetupModalLogic.ts
@@ -36,6 +36,7 @@ export interface EmailSenderFormType {
name: string
provider: 'ses' | 'maildev'
mail_from_subdomain?: string
+ reply_to?: string
}
const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/i
@@ -61,6 +62,7 @@ const getEmailSenderFromIntegration = (integration: IntegrationType): EmailSende
name: integration.config?.name ?? '',
provider: integration.config?.provider ?? 'ses',
mail_from_subdomain: integration.config?.mail_from_subdomain,
+ reply_to: integration.config?.reply_to ?? '',
}
}
@@ -189,15 +191,16 @@ export const emailSetupModalLogic = kea<emailSetupModalLogicType>([
},
],
}),
- forms(({ actions, values }) => ({
+ forms(({ actions, values, props }) => ({
emailSender: {
defaults: {
provider: 'ses',
email: '',
name: '',
mail_from_subdomain: 'feedback',
+ reply_to: '',
} as EmailSenderFormType,
- errors: ({ email, name, provider, mail_from_subdomain }) => {
+ errors: ({ email, name, provider, mail_from_subdomain, reply_to }) => {
let emailError = undefined
if (!email) {
emailError = 'Email is required'
@@ -213,9 +216,12 @@ export const emailSetupModalLogic = kea<emailSetupModalLogicType>([
values.savedIntegration === null && !mail_from_subdomain
? 'MAIL FROM subdomain is required for new senders'
: undefined,
+ reply_to: reply_to && !EMAIL_REGEX.test(reply_to) ? 'Invalid email format' : undefined,
}
},
submit: async (config) => {
+ // A new sender stays open after Continue so the user can set up DNS.
+ const isUpdate = !!values.savedIntegration
try {
let integration: IntegrationType
if (values.savedIntegration) {
@@ -231,6 +237,9 @@ export const emailSetupModalLogic = kea<emailSetupModalLogicType>([
actions.loadIntegrations()
actions.setSavedIntegration(integration)
actions.verifyDomain()
+ if (isUpdate) {
+ props.onComplete(integration.id)
+ }
return config
} catch (error) {
if (error instanceof ApiError || (error && typeof error === 'object' && 'detail' in error)) {