diff --git a/src/sentry/api/endpoints/system_options.py b/src/sentry/api/endpoints/system_options.py index 78f69c7a4aa3db..2836b1e66ae9cc 100644 --- a/src/sentry/api/endpoints/system_options.py +++ b/src/sentry/api/endpoints/system_options.py @@ -4,7 +4,7 @@ import sentry from sentry import options -from sentry.utils.email import get_mail_backend +from sentry.utils.email import is_smtp_enabled from sentry.api.base import Endpoint from sentry.api.permissions import SuperuserPermission @@ -23,17 +23,7 @@ def get(self, request): else: option_list = options.all() - # This is a fragile, hardcoded list of mail backends, but the likelihood of - # someone using something custom here is slim, and even if they did, the worst - # is they'd be prompted for SMTP information. These backends are guaranteed - # to not need SMTP information. - smtp_disabled = get_mail_backend() in ( - 'django.core.mail.backends.dummy.EmailBackend', - 'django.core.mail.backends.console.EmailBackend', - 'django.core.mail.backends.locmem.EmailBackend', - 'django.core.mail.backends.filebased.EmailBackend', - 'sentry.utils.email.PreviewBackend', - ) + smtp_disabled = not is_smtp_enabled() results = {} for k in option_list: diff --git a/src/sentry/conf/server.py b/src/sentry/conf/server.py index 5f5cd38862ab3a..cbcb8ee17a410c 100644 --- a/src/sentry/conf/server.py +++ b/src/sentry/conf/server.py @@ -715,6 +715,18 @@ def create_partitioned_queues(name): 'console': 'django.core.mail.backends.console.EmailBackend', } +# set of backends that do not support needing SMTP mail.* settings +# This list is a bit fragile and hardcoded, but it's unlikely that +# a user will be using a different backend that also mandates SMTP +# credentials. +SENTRY_SMTP_DISABLED_BACKENDS = frozenset(( + 'django.core.mail.backends.dummy.EmailBackend', + 'django.core.mail.backends.console.EmailBackend', + 'django.core.mail.backends.locmem.EmailBackend', + 'django.core.mail.backends.filebased.EmailBackend', + 'sentry.utils.email.PreviewBackend', +)) + # Should users without superuser permissions be allowed to # make projects public SENTRY_ALLOW_PUBLIC_PROJECTS = True diff --git a/src/sentry/templatetags/sentry_react.py b/src/sentry/templatetags/sentry_react.py index c3989d33721961..5f61dc5b4b3639 100644 --- a/src/sentry/templatetags/sentry_react.py +++ b/src/sentry/templatetags/sentry_react.py @@ -13,6 +13,7 @@ from sentry.api.serializers.base import serialize from sentry.models import ProjectKey from sentry.utils import json +from sentry.utils.email import is_smtp_enabled from sentry.utils.assets import get_asset_url from sentry.utils.functional import extract_lazy_object @@ -41,8 +42,13 @@ def _needs_upgrade(): # we want to force an upgrade, even if the values are set. return True + smtp_disabled = not is_smtp_enabled() + # Check all required options to see if they've been set for key in options.filter(flag=options.FLAG_REQUIRED): + # Ignore mail.* keys if smtp is disabled + if smtp_disabled and key.name[:5] == 'mail.': + continue if not options.isset(key.name): return True diff --git a/src/sentry/utils/email.py b/src/sentry/utils/email.py index fe4a0d894f5a5d..47750b12978997 100644 --- a/src/sentry/utils/email.py +++ b/src/sentry/utils/email.py @@ -394,6 +394,15 @@ def send_mail(subject, message, from_email, recipient_list, fail_silently=False) ) +def is_smtp_enabled(backend=None): + """ + Check if the current backend is SMTP based. + """ + if backend is None: + backend = get_mail_backend() + return backend not in settings.SENTRY_SMTP_DISABLED_BACKENDS + + class PreviewBackend(BaseEmailBackend): """ Email backend that can be used in local development to open messages in the