Browse Source

feat(SMTP): Add SSL support (#22524)

Fixes #22492.
PM Extra 4 years ago
parent
commit
4c5eeb87ce

+ 1 - 0
docker/config.yml

@@ -13,6 +13,7 @@
 # mail.username: ''
 # mail.password: ''
 # mail.use-tls: false
+# mail.use-ssl: false
 # The email address to send on behalf of
 # mail.from: 'root@localhost'
 

+ 2 - 0
docker/sentry.conf.py

@@ -27,6 +27,7 @@ from __future__ import absolute_import
 #  SENTRY_EMAIL_USER
 #  SENTRY_EMAIL_PASSWORD
 #  SENTRY_EMAIL_USE_TLS
+#  SENTRY_EMAIL_USE_SSL
 #  SENTRY_ENABLE_EMAIL_REPLIES
 #  SENTRY_SMTP_HOSTNAME
 #  SENTRY_MAILGUN_API_KEY
@@ -224,6 +225,7 @@ if email:
     SENTRY_OPTIONS["mail.username"] = env("SENTRY_EMAIL_USER") or ""
     SENTRY_OPTIONS["mail.port"] = int(env("SENTRY_EMAIL_PORT") or 25)
     SENTRY_OPTIONS["mail.use-tls"] = Bool(env("SENTRY_EMAIL_USE_TLS", False))
+    SENTRY_OPTIONS["mail.use-ssl"] = Bool(env("SENTRY_EMAIL_USE_SSL", False))
 else:
     SENTRY_OPTIONS["mail.backend"] = "dummy"
 

+ 1 - 0
src/sentry/api/endpoints/internal_mail.py

@@ -19,6 +19,7 @@ class InternalMailEndpoint(Endpoint):
             "mailUsername": options.get("mail.username"),
             "mailPort": options.get("mail.port"),
             "mailUseTls": options.get("mail.use-tls"),
+            "mailUseSsl": options.get("mail.use-ssl"),
             "mailFrom": options.get("mail.from"),
             "mailListNamespace": options.get("mail.list-namespace"),
             "testMailEmail": request.user.email,

+ 1 - 0
src/sentry/data/config/config.yml.default

@@ -13,6 +13,7 @@ mail.backend: '%(mail.backend)s'  # Use dummy if you want to disable email entir
 # mail.username: ''
 # mail.password: ''
 # mail.use-tls: false
+# mail.use-ssl: false
 # The email address to send on behalf of
 # mail.from: 'root@localhost'
 

+ 1 - 0
src/sentry/options/defaults.py

@@ -61,6 +61,7 @@ register("mail.port", default=25, flags=FLAG_REQUIRED | FLAG_PRIORITIZE_DISK)
 register("mail.username", flags=FLAG_REQUIRED | FLAG_ALLOW_EMPTY | FLAG_PRIORITIZE_DISK)
 register("mail.password", flags=FLAG_REQUIRED | FLAG_ALLOW_EMPTY | FLAG_PRIORITIZE_DISK)
 register("mail.use-tls", default=False, flags=FLAG_REQUIRED | FLAG_PRIORITIZE_DISK)
+register("mail.use-ssl", default=False, flags=FLAG_REQUIRED | FLAG_PRIORITIZE_DISK)
 register("mail.subject-prefix", default="[Sentry] ", flags=FLAG_PRIORITIZE_DISK)
 register("mail.from", default="root@localhost", flags=FLAG_REQUIRED | FLAG_PRIORITIZE_DISK)
 register("mail.list-namespace", type=String, default="localhost", flags=FLAG_NOSTORE)

+ 1 - 0
src/sentry/runner/initializer.py

@@ -130,6 +130,7 @@ options_mapper = {
     "mail.username": "EMAIL_HOST_USER",
     "mail.password": "EMAIL_HOST_PASSWORD",
     "mail.use-tls": "EMAIL_USE_TLS",
+    "mail.use-ssl": "EMAIL_USE_SSL",
     "mail.from": "SERVER_EMAIL",
     "mail.subject-prefix": "EMAIL_SUBJECT_PREFIX",
     "github-login.client-id": "GITHUB_APP_ID",

+ 8 - 1
src/sentry/static/sentry/app/views/admin/adminMail.tsx

@@ -11,6 +11,7 @@ type Data = {
   mailUsername: string;
   mailPort: string;
   mailUseTls: string;
+  mailUseSsl: string;
   mailFrom: string;
   mailListNamespace: string;
   testMailEmail: string;
@@ -46,6 +47,7 @@ export default class AdminMail extends AsyncView<{}, State> {
       mailUsername,
       mailPort,
       mailUseTls,
+      mailUseSsl,
       mailFrom,
       mailListNamespace,
       testMailEmail,
@@ -80,11 +82,16 @@ export default class AdminMail extends AsyncView<{}, State> {
             </pre>
           </dd>
 
-          <dt>{t('TLS?')}</dt>
+          <dt>{t('STARTTLS?')}</dt>
           <dd>
             <pre className="val">{mailUseTls ? t('Yes') : t('No')}</pre>
           </dd>
 
+          <dt>{t('SSL?')}</dt>
+          <dd>
+            <pre className="val">{mailUseSsl ? t('Yes') : t('No')}</pre>
+          </dd>
+
           <dt>{t('Mailing List Namespace')}</dt>
           <dd>
             <pre className="val">{mailListNamespace}</pre>

+ 7 - 1
src/sentry/static/sentry/app/views/admin/options.tsx

@@ -174,7 +174,13 @@ const definitions: Field[] = [
   },
   {
     key: 'mail.use-tls',
-    label: t('Use TLS?'),
+    label: t('Use STARTTLS? (exclusive with SSL)'),
+    component: BooleanField,
+    defaultValue: () => false,
+  },
+  {
+    key: 'mail.use-ssl',
+    label: t('Use SSL? (exclusive with STARTTLS)'),
     component: BooleanField,
     defaultValue: () => false,
   },

+ 1 - 0
src/sentry/utils/email.py

@@ -435,6 +435,7 @@ def get_connection(fail_silently=False):
         username=options.get("mail.username"),
         password=options.get("mail.password"),
         use_tls=options.get("mail.use-tls"),
+        use_ssl=options.get("mail.use-ssl"),
         timeout=options.get("mail.timeout"),
         fail_silently=fail_silently,
     )

+ 10 - 0
tests/js/sentry-test/fixtures/installWizard.js

@@ -10,6 +10,16 @@ export function InstallWizard(params) {
         isSet: true,
       },
     },
+    'mail.use-ssl': {
+      field: {
+        disabledReason: null,
+        default: false,
+        required: true,
+        disabled: false,
+        allowEmpty: true,
+        isSet: true,
+      },
+    },
     'mail.username': {
       field: {
         disabledReason: null,

Some files were not shown because too many files changed in this diff