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.

fix(conversations): reject personal email domains for support inboxes (#93462)

Rafael Audibert696df11c13bc
diff --git a/products/conversations/backend/api/email_settings.py b/products/conversations/backend/api/email_settings.py
index f496a4dd6157..9b394253421d 100644
--- a/products/conversations/backend/api/email_settings.py
+++ b/products/conversations/backend/api/email_settings.py
@@ -11,7 +11,9 @@ from django.db import IntegrityError, transaction
from django.utils import timezone
import structlog
+from disposable_email_domains import blocklist as disposable_email_domains_list
from drf_spectacular.utils import OpenApiResponse, extend_schema
+from free_email_domains import whitelist as free_email_domains_list
from rest_framework import serializers
from rest_framework.permissions import IsAuthenticated
from rest_framework.request import Request
@@ -58,6 +60,11 @@ from products.conversations.backend.services.email_channel_setup import (
logger = structlog.get_logger(__name__)
+SHARED_EMAIL_DOMAIN_ERROR = (
+ "We can't send support email from {domain}. Sending needs DNS records on a domain you own, "
+ "so use an address like [email protected]."
+)
+
FORWARDING_CHALLENGE_BASE_COOLDOWN_SECONDS = 30
FORWARDING_CHALLENGE_MAX_COOLDOWN_SECONDS = 60 * 60
FORWARDING_CHALLENGE_MAX_SEND_ATTEMPTS = 8
@@ -499,6 +506,12 @@ class EmailConnectView(APIView):
sibling: EmailChannel | None = None
dns_records: dict = {}
if kind == EmailChannelKind.SUPPORT:
+ # A shared provider domain can never pass DNS verification, so Mailgun would reject it
+ # later with a message about the domain being claimed by someone else. Customer
+ # communication channels are exempt: they forward mail instead of sending from it.
+ if domain in free_email_domains_list or domain in disposable_email_domains_list:
+ return Response({"error": SHARED_EMAIL_DOMAIN_ERROR.format(domain=domain)}, status=400)
+
if (
EmailChannel.objects.filter(domain=domain, kind=EmailChannelKind.SUPPORT)
.exclude(team__organization_id=team.organization_id)
diff --git a/products/conversations/backend/api/tests/test_email_endpoints.py b/products/conversations/backend/api/tests/test_email_endpoints.py
index c08789753813..1b5c959e8453 100644
--- a/products/conversations/backend/api/tests/test_email_endpoints.py
+++ b/products/conversations/backend/api/tests/test_email_endpoints.py
@@ -759,6 +759,23 @@ class TestEmailMultiConfig(BaseTest):
configs = EmailChannel.objects.filter(team=self.team)
assert configs.count() == 2
+ @patch("products.conversations.backend.api.email_settings.mailgun_add_domain", return_value={})
+ @patch(
+ "products.conversations.backend.api.email_settings.get_instance_setting",
+ return_value="mg.posthog.com",
+ )
+ def test_support_channel_rejects_shared_provider_domain(self, _mock_setting: MagicMock, mock_mailgun: MagicMock):
+ response = self.client.post(
+ "/api/conversations/v1/email/connect",
+ {"from_email": "[email protected]", "from_name": "Support"},
+ content_type="application/json",
+ )
+
+ assert response.status_code == 400
+ assert "gmail.com" in response.json()["error"]
+ mock_mailgun.assert_not_called()
+ assert not EmailChannel.objects.filter(team=self.team).exists()
+
@patch("products.conversations.backend.api.email_settings.mailgun_add_domain", return_value={})
@patch(
"products.conversations.backend.api.email_settings.get_instance_setting",