Skip to content

Commit 425586f

Browse files
committed
Merge pull request #2991 from getsentry/smtp
Don't require SMTP keys to be set when backend doesn't require them
1 parent a3decc9 commit 425586f

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed

src/sentry/api/endpoints/system_options.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import sentry
66
from sentry import options
7-
from sentry.utils.email import get_mail_backend
7+
from sentry.utils.email import is_smtp_enabled
88
from sentry.api.base import Endpoint
99
from sentry.api.permissions import SuperuserPermission
1010

@@ -23,17 +23,7 @@ def get(self, request):
2323
else:
2424
option_list = options.all()
2525

26-
# This is a fragile, hardcoded list of mail backends, but the likelihood of
27-
# someone using something custom here is slim, and even if they did, the worst
28-
# is they'd be prompted for SMTP information. These backends are guaranteed
29-
# to not need SMTP information.
30-
smtp_disabled = get_mail_backend() in (
31-
'django.core.mail.backends.dummy.EmailBackend',
32-
'django.core.mail.backends.console.EmailBackend',
33-
'django.core.mail.backends.locmem.EmailBackend',
34-
'django.core.mail.backends.filebased.EmailBackend',
35-
'sentry.utils.email.PreviewBackend',
36-
)
26+
smtp_disabled = not is_smtp_enabled()
3727

3828
results = {}
3929
for k in option_list:

src/sentry/conf/server.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,18 @@ def create_partitioned_queues(name):
715715
'console': 'django.core.mail.backends.console.EmailBackend',
716716
}
717717

718+
# set of backends that do not support needing SMTP mail.* settings
719+
# This list is a bit fragile and hardcoded, but it's unlikely that
720+
# a user will be using a different backend that also mandates SMTP
721+
# credentials.
722+
SENTRY_SMTP_DISABLED_BACKENDS = frozenset((
723+
'django.core.mail.backends.dummy.EmailBackend',
724+
'django.core.mail.backends.console.EmailBackend',
725+
'django.core.mail.backends.locmem.EmailBackend',
726+
'django.core.mail.backends.filebased.EmailBackend',
727+
'sentry.utils.email.PreviewBackend',
728+
))
729+
718730
# Should users without superuser permissions be allowed to
719731
# make projects public
720732
SENTRY_ALLOW_PUBLIC_PROJECTS = True

src/sentry/templatetags/sentry_react.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from sentry.api.serializers.base import serialize
1414
from sentry.models import ProjectKey
1515
from sentry.utils import json
16+
from sentry.utils.email import is_smtp_enabled
1617
from sentry.utils.assets import get_asset_url
1718
from sentry.utils.functional import extract_lazy_object
1819

@@ -41,8 +42,13 @@ def _needs_upgrade():
4142
# we want to force an upgrade, even if the values are set.
4243
return True
4344

45+
smtp_disabled = not is_smtp_enabled()
46+
4447
# Check all required options to see if they've been set
4548
for key in options.filter(flag=options.FLAG_REQUIRED):
49+
# Ignore mail.* keys if smtp is disabled
50+
if smtp_disabled and key.name[:5] == 'mail.':
51+
continue
4652
if not options.isset(key.name):
4753
return True
4854

src/sentry/utils/email.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,15 @@ def send_mail(subject, message, from_email, recipient_list, fail_silently=False)
394394
)
395395

396396

397+
def is_smtp_enabled(backend=None):
398+
"""
399+
Check if the current backend is SMTP based.
400+
"""
401+
if backend is None:
402+
backend = get_mail_backend()
403+
return backend not in settings.SENTRY_SMTP_DISABLED_BACKENDS
404+
405+
397406
class PreviewBackend(BaseEmailBackend):
398407
"""
399408
Email backend that can be used in local development to open messages in the

0 commit comments

Comments
 (0)