: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
feat(invites): flag invites whose email address is suppressed (#116988)
posthog[bot]b882ea757005
diff --git a/frontend/src/generated/core/api.schemas.ts b/frontend/src/generated/core/api.schemas.tsindex 76a2931deef5..dec5ed9247be 100644--- a/frontend/src/generated/core/api.schemas.ts+++ b/frontend/src/generated/core/api.schemas.ts@@ -494,6 +494,8 @@ export interface OrganizationInviteApi {/** @maxLength 30 */first_name?: stringreadonly emailing_attempt_made: boolean+ /** True when the email provider reported the target address as suppressed at send time. */+ readonly email_suppressed: booleanlevel?: OrganizationMembershipLevelEnumApi/** Check if invite is older than INVITE_DAYS_VALIDITY days. */readonly is_expired: booleandiff --git a/frontend/src/lib/api.mock.ts b/frontend/src/lib/api.mock.tsindex 45bb8abc21af..d4f2e76dbb14 100644--- a/frontend/src/lib/api.mock.ts+++ b/frontend/src/lib/api.mock.ts@@ -328,6 +328,7 @@ export const MOCK_DEFAULT_ORGANIZATION_INVITE: OrganizationInviteType = {target_email: '[email protected]',first_name: '',emailing_attempt_made: true,+ email_suppressed: false,is_expired: true,created_by: MOCK_DEFAULT_BASIC_USER,created_at: '2022-03-11T16:44:01.264613Z',diff --git a/frontend/src/scenes/settings/organization/Invites.tsx b/frontend/src/scenes/settings/organization/Invites.tsxindex 92aaed4d72c0..f0a0ff97010c 100644--- a/frontend/src/scenes/settings/organization/Invites.tsx+++ b/frontend/src/scenes/settings/organization/Invites.tsx@@ -1,7 +1,7 @@import { useActions, useValues } from 'kea'import { IconX } from '@posthog/icons'-import { LemonTag } from '@posthog/lemon-ui'+import { LemonTag, Tooltip } from '@posthog/lemon-ui'import { CopyToClipboardInline } from 'lib/components/CopyToClipboard'import { useRestrictedArea } from 'lib/components/RestrictedArea'@@ -85,9 +85,18 @@ export function InvitesTable(): JSX.Element {key: 'target_email',render: function TargetEmail(_, invite): JSX.Element | string {return invite.target_email ? (- <div className="ph-no-capture flex items-center">- {invite.target_email}- {invite.first_name ? ` (${invite.first_name})` : ''}+ <div className="flex flex-wrap items-center gap-2">+ <span className="ph-no-capture">+ {invite.target_email}+ {invite.first_name ? ` (${invite.first_name})` : ''}+ </span>+ {invite.email_suppressed && (+ <Tooltip title="Our email provider is blocking email to this address, usually because an earlier email bounced. Share the invite link with them directly, or contact support to unblock the address.">+ <LemonTag type="danger" data-attr="invite-email-suppressed">+ Email not delivered+ </LemonTag>+ </Tooltip>+ )}</div>) : (<i>no one</i>diff --git a/frontend/src/types.ts b/frontend/src/types.tsindex 6bb2d9c7867b..18eec7303052 100644--- a/frontend/src/types.ts+++ b/frontend/src/types.ts@@ -2961,6 +2961,7 @@ export interface OrganizationInviteType {level: OrganizationMembershipLevelis_expired: booleanemailing_attempt_made: boolean+ email_suppressed: booleancreated_by: UserBasicType | nullcreated_at: stringupdated_at: stringdiff --git a/posthog/api/organization_invite.py b/posthog/api/organization_invite.pyindex 97c01dd9a557..35a5ddd4c2c1 100644--- a/posthog/api/organization_invite.py+++ b/posthog/api/organization_invite.py@@ -174,6 +174,7 @@ class OrganizationInviteSerializer(serializers.ModelSerializer):"target_email","first_name","emailing_attempt_made",+ "email_suppressed","level","is_expired","created_by",@@ -187,6 +188,7 @@ class OrganizationInviteSerializer(serializers.ModelSerializer):read_only_fields = ["id","emailing_attempt_made",+ "email_suppressed","created_at","updated_at",]@@ -353,7 +355,8 @@ class OrganizationInviteSerializer(serializers.ModelSerializer):if is_email_available(with_absolute_urls=True) and send_email:invite.emailing_attempt_made = Truesend_invite(invite_id=invite.id)- invite.save()+ # A full-row save would overwrite `email_suppressed` if the suppression check that `send_invite` queues finished first.+ invite.save(update_fields=["emailing_attempt_made", "updated_at"])report_team_member_invited(self.context["request"].user,diff --git a/posthog/api/test/test_organization_invites.py b/posthog/api/test/test_organization_invites.pyindex 17c5e4a35e4c..f4dad5b3ae77 100644--- a/posthog/api/test/test_organization_invites.py+++ b/posthog/api/test/test_organization_invites.py@@ -17,6 +17,7 @@ from parameterized import parameterizedfrom rest_framework import statusfrom posthog.constants import AvailableFeature+from posthog.helpers.email_utils import ESPSuppressionReason, ESPSuppressionResultfrom posthog.models import Userfrom posthog.models.file_system.file_system_shortcut import FileSystemShortcutfrom posthog.models.instance_setting import set_instance_setting@@ -224,6 +225,7 @@ class TestOrganizationInvitesAPI(APIBaseTest):"is_expired": False,"level": 1,"emailing_attempt_made": True,+ "email_suppressed": False,"message": None,"private_project_access": [],},@@ -264,6 +266,35 @@ class TestOrganizationInvitesAPI(APIBaseTest):self.assertListEqual(mail.outbox[0].to, [email])self.assertEqual(mail.outbox[0].reply_to, [self.user.email]) # Reply-To is set to the inviting user+ @parameterized.expand(+ [+ ("suppressed", ESPSuppressionReason.SUPPRESSED, True),+ ("not_suppressed", None, False),+ ("api_failure", ESPSuppressionReason.API_FAILURE_FALLBACK, False),+ ]+ )+ @patch("posthog.tasks.email.EmailMessage")+ @patch("posthog.tasks.email.check_esp_suppression")+ @patch("posthog.tasks.email.ph_scoped_capture")+ def test_add_organization_invite_flags_esp_suppressed_email(+ self, _name, reason, expected_suppressed, mock_scoped_capture, mock_check, _mock_email_message+ ):+ set_instance_setting("EMAIL_HOST", "localhost")+ mock_check.return_value = ESPSuppressionResult(+ is_suppressed=reason is not None, from_cache=False, reason=reason+ )+ capture = mock_scoped_capture.return_value.__enter__.return_value++ with self.settings(EMAIL_ENABLED=True, SITE_URL="http://test.posthog.com", CUSTOMER_IO_API_KEY="test-key"):+ response = self.client.post("/api/organizations/@current/invites/", {"target_email": "[email protected]"})++ self.assertEqual(response.status_code, status.HTTP_201_CREATED)+ mock_check.assert_called_once_with("[email protected]")+ list_response = self.client.get("/api/organizations/@current/invites/")+ self.assertEqual(list_response.json()["results"][0]["email_suppressed"], expected_suppressed)+ events = [c.kwargs["event"] for c in capture.call_args_list]+ self.assertEqual(events, ["invite email suppressed"] if expected_suppressed else [])+@patch("posthoganalytics.capture")def test_add_organization_invite_with_email_on_instance_but_send_email_prop_false(self, mock_capture):"""diff --git a/posthog/migrations/1417_organizationinvite_email_suppressed.py b/posthog/migrations/1417_organizationinvite_email_suppressed.pynew file mode 100644index 000000000000..4ef734593a8d--- /dev/null+++ b/posthog/migrations/1417_organizationinvite_email_suppressed.py@@ -0,0 +1,21 @@+# Generated by Django 5.2.18 on 2026-10-14 12:35++from django.db import migrations, models+++class Migration(migrations.Migration):+ dependencies = [+ ("posthog", "1416_uploadedmedia_serving_disabled_at"),+ ]++ operations = [+ migrations.AddField(+ model_name="organizationinvite",+ name="email_suppressed",+ field=models.BooleanField(+ db_default=False,+ default=False,+ help_text="True when the email provider reported the target address as suppressed at send time.",+ ),+ ),+ ]diff --git a/posthog/migrations/max_migration.txt b/posthog/migrations/max_migration.txtindex 365e76401264..d469d78045aa 100644--- a/posthog/migrations/max_migration.txt+++ b/posthog/migrations/max_migration.txt@@ -1 +1 @@-1416_uploadedmedia_serving_disabled_at+1417_organizationinvite_email_suppresseddiff --git a/posthog/models/organization_invite.py b/posthog/models/organization_invite.pyindex 1ac6a658239a..8187b5a68b75 100644--- a/posthog/models/organization_invite.py+++ b/posthog/models/organization_invite.py@@ -73,6 +73,11 @@ class OrganizationInvite(ModelActivityMixin, UUIDTModel):null=True,)emailing_attempt_made = models.BooleanField(default=False)+ email_suppressed = models.BooleanField(+ default=False,+ db_default=False,+ help_text="True when the email provider reported the target address as suppressed at send time.",+ )created_at = models.DateTimeField(auto_now_add=True)updated_at = models.DateTimeField(auto_now=True)message = models.TextField(blank=True, null=True)diff --git a/posthog/tasks/email.py b/posthog/tasks/email.pyindex 1c540a6d1152..1879061106b3 100644--- a/posthog/tasks/email.py+++ b/posthog/tasks/email.py@@ -26,11 +26,17 @@ from posthog.email import (EmailMessage,get_email_team_and_org_context,is_email_available,+ is_http_email_service_available,single_line,)from posthog.event_usage import groupsfrom posthog.geoip import get_geoip_properties-from posthog.helpers.email_utils import sanitize_display_name, sanitize_message_body+from posthog.helpers.email_utils import (+ ESPSuppressionReason,+ check_esp_suppression,+ sanitize_display_name,+ sanitize_message_body,+)from posthog.helpers.two_factor_session import CODE_TTL_SECONDSfrom posthog.models import (Organization,@@ -430,6 +436,25 @@ def should_send_pipeline_error_notification(return failure_rate > threshold+@shared_task(ignore_result=True)+@skip_team_scope_audit+def check_invite_email_suppression(invite_id: str) -> None:+ invite = OrganizationInvite.objects.select_related("created_by").filter(id=invite_id).first()+ if invite is None or not invite.target_email or not is_http_email_service_available():+ return+ # Only a confirmed suppression counts. The MFA flow treats an API failure as suppressed, but here that would flag healthy addresses.+ if check_esp_suppression(invite.target_email).reason != ESPSuppressionReason.SUPPRESSED:+ return+ OrganizationInvite.objects.filter(id=invite_id).update(email_suppressed=True)+ with ph_scoped_capture() as capture:+ capture(+ distinct_id=str(invite.created_by.distinct_id) if invite.created_by else f"invite_{invite_id}",+ event="invite email suppressed",+ properties={"invite_id": invite_id, "is_setup_delegation": invite.is_setup_delegation},+ groups={"organization": str(invite.organization_id)},+ )++@shared_task(**EMAIL_TASK_KWARGS)@skip_team_scope_auditdef send_invite(invite_id: str) -> None:@@ -543,6 +568,8 @@ def send_invite(invite_id: str) -> None:else:message.send()OrganizationInvite.objects.filter(pk=invite_id).update(emailing_attempt_made=True)+ # The lookup can take seconds, so it runs in its own task rather than delaying the invite email.+ check_invite_email_suppression.delay(str(invite_id))@shared_task(**EMAIL_TASK_KWARGS)diff --git a/posthog/tasks/test/__snapshots__/test_task_registration.ambr b/posthog/tasks/test/__snapshots__/test_task_registration.ambrindex f248f0bbb503..779a37f7081a 100644--- a/posthog/tasks/test/__snapshots__/test_task_registration.ambr+++ b/posthog/tasks/test/__snapshots__/test_task_registration.ambr@@ -31,6 +31,7 @@'posthog.tasks.demo_create_data.create_data_for_demo_team','posthog.tasks.early_access_feature.create_waitlist_survey_for_concept_feature','posthog.tasks.early_access_feature.send_events_for_early_access_feature_stage_change',+ 'posthog.tasks.email.check_invite_email_suppression','posthog.tasks.email.login_from_new_device_notification','posthog.tasks.email.send_async_migration_complete_email','posthog.tasks.email.send_async_migration_errored_email',diff --git a/posthog/tasks/test/test_email.py b/posthog/tasks/test/test_email.pyindex 1528fa3cf3f9..b782b4775735 100644--- a/posthog/tasks/test/test_email.py+++ b/posthog/tasks/test/test_email.py@@ -17,6 +17,7 @@ from parameterized import parameterizedfrom posthog.api.authentication import password_reset_token_generatorfrom posthog.constants import AvailableFeature+from posthog.helpers.email_utils import ESPSuppressionReason, ESPSuppressionResultfrom posthog.models import Comment, Organization, Team, Userfrom posthog.models.app_metrics2.sql import TRUNCATE_APP_METRICS2_TABLE_SQLfrom posthog.models.instance_setting import set_instance_setting@@ -158,6 +159,29 @@ class TestEmail(APIBaseTest, ClickhouseTestMixin):# Routed to the delegation templateassert MockEmailMessage.call_args.kwargs["template_name"] == "delegation_invite"+ @parameterized.expand([("member_invite", False), ("delegation_invite", True)])+ @patch("posthog.tasks.email.check_esp_suppression")+ def test_send_invite_flags_suppressed_target_email(+ self, _name: str, is_setup_delegation: bool, mock_check: MagicMock, MockEmailMessage: MagicMock+ ) -> None:+ mock_email_messages(MockEmailMessage)+ mock_check.return_value = ESPSuppressionResult(+ is_suppressed=True, from_cache=False, reason=ESPSuppressionReason.SUPPRESSED+ )+ org, user = create_org_team_and_user("2022-01-02 00:00:00", "[email protected]")+ invite = OrganizationInvite.objects.create(+ organization=org,+ created_by=user,+ target_email="[email protected]",+ is_setup_delegation=is_setup_delegation,+ )++ with self.settings(CUSTOMER_IO_API_KEY="test-key"):+ send_invite(invite.id)++ invite.refresh_from_db()+ assert invite.email_suppressed is True+def test_send_member_join(self, MockEmailMessage: MagicMock) -> None:mocked_email_messages = mock_email_messages(MockEmailMessage)diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex 29db19f8d951..4246b3bee824 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -76934,6 +76934,8 @@ export namespace Schemas {/** @maxLength 30 */first_name?: string;readonly emailing_attempt_made: boolean;+ /** True when the email provider reported the target address as suppressed at send time. */+ readonly email_suppressed: boolean;level?: OrganizationMembershipLevelEnum;/** Check if invite is older than INVITE_DAYS_VALIDITY days. */readonly is_expired: boolean;