From db393f05be6344a2a84744fb4137d4274cad0ee7 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 10 Jun 2021 11:25:06 +0100 Subject: [PATCH] Adding options to SMTP form for configuring TLS/STARTTLS. --- .../builder/portal/manage/email/index.svelte | 43 ++++++++++++++----- packages/worker/src/utilities/email.js | 7 ++- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/packages/builder/src/pages/builder/portal/manage/email/index.svelte b/packages/builder/src/pages/builder/portal/manage/email/index.svelte index 46af44ec93..f38f922bb8 100644 --- a/packages/builder/src/pages/builder/portal/manage/email/index.svelte +++ b/packages/builder/src/pages/builder/portal/manage/email/index.svelte @@ -5,16 +5,18 @@ Heading, Divider, Label, - Page, notifications, Layout, Input, + Select, Body, Table, + Checkbox, } from "@budibase/bbui" import { email } from "stores/portal" import TemplateLink from "./_components/TemplateLink.svelte" import api from "builderStore/api" + import { cloneDeep } from "lodash/fp" const ConfigTypes = { SMTP: "smtp", @@ -36,10 +38,16 @@ let smtpConfig let loading + let requireAuth = false async function saveSmtp() { + // clone it so we can remove stuff if required + const smtp = cloneDeep(smtpConfig) + if (!requireAuth) { + delete smtp.config.auth + } // Save your SMTP config - const response = await api.post(`/api/admin/configs`, smtpConfig) + const response = await api.post(`/api/admin/configs`, smtp) if (response.status !== 200) { const error = await response.text() @@ -66,6 +74,7 @@ smtpConfig = { type: ConfigTypes.SMTP, config: { + secure: true, auth: { type: "login", }, @@ -75,6 +84,7 @@ smtpConfig = smtpDoc } loading = false + requireAuth = smtpConfig.config.auth != null } fetchSmtp() @@ -103,22 +113,35 @@ +
+ +
-
- - -
-
- - -
+ + {#if requireAuth} +
+ + +
+
+ + +
+ {/if}
diff --git a/packages/worker/src/utilities/email.js b/packages/worker/src/utilities/email.js index 4e48844843..534456fe15 100644 --- a/packages/worker/src/utilities/email.js +++ b/packages/worker/src/utilities/email.js @@ -20,11 +20,16 @@ const FULL_EMAIL_PURPOSES = [ function createSMTPTransport(config) { let options + let secure = config.secure + // default it if not specified + if (secure == null) { + secure = config.port === 465 + } if (!TEST_MODE) { options = { port: config.port, host: config.host, - secure: config.secure || false, + secure: secure, auth: config.auth, } options.tls = {