2022-07-07 00:19:05 +03:00
|
|
|
<script>
|
|
|
|
import { slide } from "svelte/transition";
|
|
|
|
import ApiClient from "@/utils/ApiClient";
|
|
|
|
import CommonHelper from "@/utils/CommonHelper";
|
2022-07-18 19:44:10 +03:00
|
|
|
import { pageTitle } from "@/stores/app";
|
2022-08-14 19:30:45 +03:00
|
|
|
import { setErrors } from "@/stores/errors";
|
2022-07-07 00:19:05 +03:00
|
|
|
import { addSuccessToast } from "@/stores/toasts";
|
2022-08-09 16:16:09 +03:00
|
|
|
import PageWrapper from "@/components/base/PageWrapper.svelte";
|
2022-07-07 00:19:05 +03:00
|
|
|
import Field from "@/components/base/Field.svelte";
|
|
|
|
import ObjectSelect from "@/components/base/ObjectSelect.svelte";
|
|
|
|
import RedactedPasswordInput from "@/components/base/RedactedPasswordInput.svelte";
|
|
|
|
import SettingsSidebar from "@/components/settings/SettingsSidebar.svelte";
|
2022-08-14 19:30:45 +03:00
|
|
|
import EmailTemplateAccordion from "@/components/settings/EmailTemplateAccordion.svelte";
|
2022-07-07 00:19:05 +03:00
|
|
|
|
|
|
|
const tlsOptions = [
|
2022-08-14 19:30:45 +03:00
|
|
|
{ label: "Auto (StartTLS)", value: false },
|
2022-07-07 00:19:05 +03:00
|
|
|
{ label: "Always", value: true },
|
|
|
|
];
|
|
|
|
|
2022-07-18 19:44:10 +03:00
|
|
|
$pageTitle = "Mail settings";
|
|
|
|
|
2022-08-14 19:30:45 +03:00
|
|
|
let firstAccordion;
|
|
|
|
let originalFormSettings = {};
|
2022-07-07 00:19:05 +03:00
|
|
|
let formSettings = {};
|
|
|
|
let isLoading = false;
|
|
|
|
let isSaving = false;
|
2022-08-14 19:30:45 +03:00
|
|
|
|
|
|
|
$: initialHash = JSON.stringify(originalFormSettings);
|
2022-07-07 00:19:05 +03:00
|
|
|
|
|
|
|
$: hasChanges = initialHash != JSON.stringify(formSettings);
|
|
|
|
|
|
|
|
loadSettings();
|
|
|
|
|
|
|
|
async function loadSettings() {
|
|
|
|
isLoading = true;
|
|
|
|
|
|
|
|
try {
|
2022-08-02 17:00:14 +03:00
|
|
|
const settings = (await ApiClient.settings.getAll()) || {};
|
2022-07-07 00:19:05 +03:00
|
|
|
init(settings);
|
|
|
|
} catch (err) {
|
|
|
|
ApiClient.errorResponseHandler(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
isLoading = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function save() {
|
|
|
|
if (isSaving || !hasChanges) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
isSaving = true;
|
|
|
|
|
|
|
|
try {
|
2022-08-02 17:00:14 +03:00
|
|
|
const settings = await ApiClient.settings.update(CommonHelper.filterRedactedProps(formSettings));
|
2022-07-07 00:19:05 +03:00
|
|
|
init(settings);
|
2022-08-14 19:30:45 +03:00
|
|
|
setErrors({});
|
|
|
|
firstAccordion?.collapseSiblings();
|
2022-07-07 00:19:05 +03:00
|
|
|
addSuccessToast("Successfully saved mail settings.");
|
|
|
|
} catch (err) {
|
|
|
|
ApiClient.errorResponseHandler(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
isSaving = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function init(settings = {}) {
|
|
|
|
formSettings = {
|
|
|
|
meta: settings?.meta || {},
|
|
|
|
smtp: settings?.smtp || {},
|
|
|
|
};
|
2022-08-14 19:30:45 +03:00
|
|
|
|
|
|
|
originalFormSettings = JSON.parse(JSON.stringify(formSettings));
|
|
|
|
}
|
|
|
|
|
|
|
|
function reset() {
|
|
|
|
formSettings = JSON.parse(JSON.stringify(originalFormSettings || {}));
|
2022-07-07 00:19:05 +03:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<SettingsSidebar />
|
|
|
|
|
2022-08-09 16:16:09 +03:00
|
|
|
<PageWrapper>
|
2022-07-07 00:19:05 +03:00
|
|
|
<header class="page-header">
|
|
|
|
<nav class="breadcrumbs">
|
|
|
|
<div class="breadcrumb-item">Settings</div>
|
2022-07-18 19:44:10 +03:00
|
|
|
<div class="breadcrumb-item">{$pageTitle}</div>
|
2022-07-07 00:19:05 +03:00
|
|
|
</nav>
|
|
|
|
</header>
|
|
|
|
|
|
|
|
<div class="wrapper">
|
|
|
|
<form class="panel" autocomplete="off" on:submit|preventDefault={() => save()}>
|
|
|
|
<div class="content txt-xl m-b-base">
|
|
|
|
<p>Configure common settings for sending emails.</p>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{#if isLoading}
|
|
|
|
<div class="loader" />
|
|
|
|
{:else}
|
2022-08-14 19:30:45 +03:00
|
|
|
<div class="grid m-b-base">
|
2022-07-07 00:19:05 +03:00
|
|
|
<div class="col-lg-6">
|
|
|
|
<Field class="form-field required" name="meta.senderName" let:uniqueId>
|
|
|
|
<label for={uniqueId}>Sender name</label>
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
id={uniqueId}
|
|
|
|
required
|
|
|
|
bind:value={formSettings.meta.senderName}
|
|
|
|
/>
|
|
|
|
</Field>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="col-lg-6">
|
|
|
|
<Field class="form-field required" name="meta.senderAddress" let:uniqueId>
|
|
|
|
<label for={uniqueId}>Sender address</label>
|
|
|
|
<input
|
|
|
|
type="email"
|
|
|
|
id={uniqueId}
|
|
|
|
required
|
|
|
|
bind:value={formSettings.meta.senderAddress}
|
|
|
|
/>
|
|
|
|
</Field>
|
|
|
|
</div>
|
2022-08-14 19:30:45 +03:00
|
|
|
</div>
|
2022-07-07 00:19:05 +03:00
|
|
|
|
2022-08-14 19:30:45 +03:00
|
|
|
<div class="accordions">
|
|
|
|
<EmailTemplateAccordion
|
|
|
|
bind:this={firstAccordion}
|
|
|
|
single
|
|
|
|
key="meta.verificationTemplate"
|
|
|
|
title={'Default "Verification" email template'}
|
|
|
|
bind:config={formSettings.meta.verificationTemplate}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<EmailTemplateAccordion
|
|
|
|
single
|
|
|
|
key="meta.resetPasswordTemplate"
|
|
|
|
title={'Default "Password reset" email template'}
|
|
|
|
bind:config={formSettings.meta.resetPasswordTemplate}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<EmailTemplateAccordion
|
|
|
|
single
|
|
|
|
key="meta.confirmEmailChangeTemplate"
|
|
|
|
title={'Default "Confirm email change" email template'}
|
|
|
|
bind:config={formSettings.meta.confirmEmailChangeTemplate}
|
|
|
|
/>
|
2022-07-07 00:19:05 +03:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<hr />
|
|
|
|
|
2022-08-15 21:31:25 +03:00
|
|
|
<Field class="form-field form-field-toggle m-b-sm" let:uniqueId>
|
2022-07-07 00:19:05 +03:00
|
|
|
<input type="checkbox" id={uniqueId} required bind:checked={formSettings.smtp.enabled} />
|
|
|
|
<label for={uniqueId}>Use SMTP mail server</label>
|
|
|
|
</Field>
|
|
|
|
|
2022-08-15 21:31:25 +03:00
|
|
|
{#if !formSettings.smtp.enabled}
|
|
|
|
<div class="content" transition:slide|local={{ duration: 150 }}>
|
|
|
|
<p>
|
|
|
|
By default PocketBase uses the OS <code>sendmail</code> command for sending
|
|
|
|
emails.
|
|
|
|
<br />
|
|
|
|
<strong class="txt-bold">
|
|
|
|
For better emails deliverability it is recommended to use a SMTP mail server.
|
|
|
|
</strong>
|
|
|
|
</p>
|
|
|
|
<div class="clearfix m-t-lg" />
|
|
|
|
</div>
|
|
|
|
{:else}
|
2022-07-07 00:19:05 +03:00
|
|
|
<div class="grid" transition:slide|local={{ duration: 150 }}>
|
|
|
|
<div class="col-lg-6">
|
|
|
|
<Field class="form-field required" name="smtp.host" let:uniqueId>
|
|
|
|
<label for={uniqueId}>SMTP server host</label>
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
id={uniqueId}
|
|
|
|
required
|
|
|
|
bind:value={formSettings.smtp.host}
|
|
|
|
/>
|
|
|
|
</Field>
|
|
|
|
</div>
|
|
|
|
<div class="col-lg-3">
|
|
|
|
<Field class="form-field required" name="smtp.port" let:uniqueId>
|
|
|
|
<label for={uniqueId}>Port</label>
|
|
|
|
<input
|
|
|
|
type="number"
|
|
|
|
id={uniqueId}
|
|
|
|
required
|
|
|
|
bind:value={formSettings.smtp.port}
|
|
|
|
/>
|
|
|
|
</Field>
|
|
|
|
</div>
|
|
|
|
<div class="col-lg-3">
|
|
|
|
<Field class="form-field required" name="smtp.tls" let:uniqueId>
|
|
|
|
<label for={uniqueId}>TLS Encryption</label>
|
|
|
|
<ObjectSelect
|
|
|
|
id={uniqueId}
|
|
|
|
items={tlsOptions}
|
|
|
|
bind:keyOfSelected={formSettings.smtp.tls}
|
|
|
|
/>
|
|
|
|
</Field>
|
|
|
|
</div>
|
|
|
|
<div class="col-lg-6">
|
|
|
|
<Field class="form-field" name="smtp.username" let:uniqueId>
|
|
|
|
<label for={uniqueId}>Username</label>
|
|
|
|
<input type="text" id={uniqueId} bind:value={formSettings.smtp.username} />
|
|
|
|
</Field>
|
|
|
|
</div>
|
|
|
|
<div class="col-lg-6">
|
|
|
|
<Field class="form-field" name="smtp.password" let:uniqueId>
|
|
|
|
<label for={uniqueId}>Password</label>
|
|
|
|
<RedactedPasswordInput
|
|
|
|
id={uniqueId}
|
|
|
|
bind:value={formSettings.smtp.password}
|
|
|
|
/>
|
|
|
|
</Field>
|
|
|
|
</div>
|
|
|
|
<!-- margin helper -->
|
|
|
|
<div class="col-lg-12" />
|
|
|
|
</div>
|
|
|
|
{/if}
|
|
|
|
|
|
|
|
<div class="flex">
|
|
|
|
<div class="flex-fill" />
|
2022-08-14 19:30:45 +03:00
|
|
|
{#if hasChanges}
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
class="btn btn-secondary btn-hint"
|
|
|
|
disabled={isSaving}
|
|
|
|
on:click={() => reset()}
|
|
|
|
>
|
|
|
|
<span class="txt">Cancel</span>
|
|
|
|
</button>
|
|
|
|
{/if}
|
2022-07-07 00:19:05 +03:00
|
|
|
<button
|
|
|
|
type="submit"
|
|
|
|
class="btn btn-expanded"
|
|
|
|
class:btn-loading={isSaving}
|
|
|
|
disabled={!hasChanges || isSaving}
|
|
|
|
on:click={() => save()}
|
|
|
|
>
|
|
|
|
<span class="txt">Save changes</span>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
{/if}
|
|
|
|
</form>
|
|
|
|
</div>
|
2022-08-09 16:16:09 +03:00
|
|
|
</PageWrapper>
|