Adding options to SMTP form for configuring TLS/STARTTLS.

This commit is contained in:
mike12345567 2021-06-10 11:25:06 +01:00
parent 72caa080fe
commit db393f05be
2 changed files with 39 additions and 11 deletions

View File

@ -5,16 +5,18 @@
Heading, Heading,
Divider, Divider,
Label, Label,
Page,
notifications, notifications,
Layout, Layout,
Input, Input,
Select,
Body, Body,
Table, Table,
Checkbox,
} from "@budibase/bbui" } from "@budibase/bbui"
import { email } from "stores/portal" import { email } from "stores/portal"
import TemplateLink from "./_components/TemplateLink.svelte" import TemplateLink from "./_components/TemplateLink.svelte"
import api from "builderStore/api" import api from "builderStore/api"
import { cloneDeep } from "lodash/fp"
const ConfigTypes = { const ConfigTypes = {
SMTP: "smtp", SMTP: "smtp",
@ -36,10 +38,16 @@
let smtpConfig let smtpConfig
let loading let loading
let requireAuth = false
async function saveSmtp() { 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 // 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) { if (response.status !== 200) {
const error = await response.text() const error = await response.text()
@ -66,6 +74,7 @@
smtpConfig = { smtpConfig = {
type: ConfigTypes.SMTP, type: ConfigTypes.SMTP,
config: { config: {
secure: true,
auth: { auth: {
type: "login", type: "login",
}, },
@ -75,6 +84,7 @@
smtpConfig = smtpDoc smtpConfig = smtpDoc
} }
loading = false loading = false
requireAuth = smtpConfig.config.auth != null
} }
fetchSmtp() fetchSmtp()
@ -103,10 +113,26 @@
<Label size="L">Host</Label> <Label size="L">Host</Label>
<Input bind:value={smtpConfig.config.host} /> <Input bind:value={smtpConfig.config.host} />
</div> </div>
<div class="form-row">
<Label siz="L">Security type</Label>
<Select
bind:value={smtpConfig.config.secure}
options={[
{ label: "SSL/TLS", value: true },
{ label: "None/STARTTLS", value: false },
]}
/>
</div>
<div class="form-row"> <div class="form-row">
<Label size="L">Port</Label> <Label size="L">Port</Label>
<Input type="number" bind:value={smtpConfig.config.port} /> <Input type="number" bind:value={smtpConfig.config.port} />
</div> </div>
<div class="form-row">
<Label size="L">From email address</Label>
<Input type="email" bind:value={smtpConfig.config.from} />
</div>
<Checkbox bind:value={requireAuth} text="Require sign-in" />
{#if requireAuth}
<div class="form-row"> <div class="form-row">
<Label size="L">User</Label> <Label size="L">User</Label>
<Input bind:value={smtpConfig.config.auth.user} /> <Input bind:value={smtpConfig.config.auth.user} />
@ -115,10 +141,7 @@
<Label size="L">Password</Label> <Label size="L">Password</Label>
<Input type="password" bind:value={smtpConfig.config.auth.pass} /> <Input type="password" bind:value={smtpConfig.config.auth.pass} />
</div> </div>
<div class="form-row"> {/if}
<Label size="L">From email address</Label>
<Input type="email" bind:value={smtpConfig.config.from} />
</div>
</Layout> </Layout>
<div> <div>
<Button cta on:click={saveSmtp}>Save</Button> <Button cta on:click={saveSmtp}>Save</Button>

View File

@ -20,11 +20,16 @@ const FULL_EMAIL_PURPOSES = [
function createSMTPTransport(config) { function createSMTPTransport(config) {
let options let options
let secure = config.secure
// default it if not specified
if (secure == null) {
secure = config.port === 465
}
if (!TEST_MODE) { if (!TEST_MODE) {
options = { options = {
port: config.port, port: config.port,
host: config.host, host: config.host,
secure: config.secure || false, secure: secure,
auth: config.auth, auth: config.auth,
} }
options.tls = { options.tls = {