diff --git a/zerver/management/commands/send_custom_email.py b/zerver/management/commands/send_custom_email.py index f8eec40fc3..52855e8680 100644 --- a/zerver/management/commands/send_custom_email.py +++ b/zerver/management/commands/send_custom_email.py @@ -3,6 +3,7 @@ from typing import Any from django.conf import settings from django.core.management.base import CommandError +from django.db.models import Q from zerver.lib.management import ZulipBaseCommand from zerver.lib.send_email import send_custom_email @@ -27,6 +28,11 @@ class Command(ZulipBaseCommand): action="store_true", help="Send to all organization administrators of sponsored organizations.", ) + parser.add_argument( + "--marketing", + action="store_true", + help="Send to active users and realm owners with the enable_marketing_emails setting enabled.", + ) parser.add_argument( "--markdown-template-path", "--path", @@ -63,6 +69,20 @@ class Command(ZulipBaseCommand): users = UserProfile.objects.filter( is_active=True, is_bot=False, is_mirror_dummy=False, realm__deactivated=False ) + elif options["marketing"]: + # Marketing email sent at most once to each email address for users + # who are either recently active (!long_term_idle) or are a realm owner. + users = ( + UserProfile.objects.filter( + is_active=True, + is_bot=False, + is_mirror_dummy=False, + realm__deactivated=False, + enable_marketing_emails=True, + ) + .filter(Q(long_term_idle=False) | Q(role=UserProfile.ROLE_REALM_OWNER)) + .distinct("delivery_email") + ) elif options["all_sponsored_org_admins"]: # Sends at most one copy to each email address, even if it # is an administrator in several organizations.