Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions src/sentry/api/endpoints/system_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand Down
12 changes: 12 additions & 0 deletions src/sentry/conf/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/sentry/templatetags/sentry_react.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions src/sentry/utils/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down