mirror of
https://github.com/pocket-id/pocket-id.git
synced 2025-12-16 18:23:03 +03:00
fix: add option to manually select SMTP TLS method (#268)
Co-authored-by: Elias Schneider <login@eliasschneider.com>
This commit is contained in:
@@ -21,7 +21,7 @@ type AppConfigUpdateDto struct {
|
|||||||
SmtpFrom string `json:"smtpFrom" binding:"omitempty,email"`
|
SmtpFrom string `json:"smtpFrom" binding:"omitempty,email"`
|
||||||
SmtpUser string `json:"smtpUser"`
|
SmtpUser string `json:"smtpUser"`
|
||||||
SmtpPassword string `json:"smtpPassword"`
|
SmtpPassword string `json:"smtpPassword"`
|
||||||
SmtpTls string `json:"smtpTls"`
|
SmtpTls string `json:"smtpTls" binding:"required,oneof=none starttls tls"`
|
||||||
SmtpSkipCertVerify string `json:"smtpSkipCertVerify"`
|
SmtpSkipCertVerify string `json:"smtpSkipCertVerify"`
|
||||||
LdapEnabled string `json:"ldapEnabled" binding:"required"`
|
LdapEnabled string `json:"ldapEnabled" binding:"required"`
|
||||||
LdapUrl string `json:"ldapUrl"`
|
LdapUrl string `json:"ldapUrl"`
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ func NewAppConfigService(db *gorm.DB) *AppConfigService {
|
|||||||
if err := service.InitDbConfig(); err != nil {
|
if err := service.InitDbConfig(); err != nil {
|
||||||
log.Fatalf("Failed to initialize app config service: %v", err)
|
log.Fatalf("Failed to initialize app config service: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return service
|
return service
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,8 +97,8 @@ var defaultDbConfig = model.AppConfig{
|
|||||||
},
|
},
|
||||||
SmtpTls: model.AppConfigVariable{
|
SmtpTls: model.AppConfigVariable{
|
||||||
Key: "smtpTls",
|
Key: "smtpTls",
|
||||||
Type: "bool",
|
Type: "string",
|
||||||
DefaultValue: "true",
|
DefaultValue: "none",
|
||||||
},
|
},
|
||||||
SmtpSkipCertVerify: model.AppConfigVariable{
|
SmtpSkipCertVerify: model.AppConfigVariable{
|
||||||
Key: "smtpSkipCertVerify",
|
Key: "smtpSkipCertVerify",
|
||||||
|
|||||||
@@ -115,18 +115,22 @@ func (srv *EmailService) getSmtpClient() (client *smtp.Client, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Connect to the SMTP server
|
// Connect to the SMTP server
|
||||||
if srv.appConfigService.DbConfig.SmtpTls.Value == "false" {
|
// Connect to the SMTP server based on TLS setting
|
||||||
|
switch srv.appConfigService.DbConfig.SmtpTls.Value {
|
||||||
|
case "none":
|
||||||
client, err = srv.connectToSmtpServer(smtpAddress)
|
client, err = srv.connectToSmtpServer(smtpAddress)
|
||||||
} else if port == "465" {
|
case "tls":
|
||||||
client, err = srv.connectToSmtpServerUsingImplicitTLS(
|
client, err = srv.connectToSmtpServerUsingImplicitTLS(
|
||||||
smtpAddress,
|
smtpAddress,
|
||||||
tlsConfig,
|
tlsConfig,
|
||||||
)
|
)
|
||||||
} else {
|
case "starttls":
|
||||||
client, err = srv.connectToSmtpServerUsingStartTLS(
|
client, err = srv.connectToSmtpServerUsingStartTLS(
|
||||||
smtpAddress,
|
smtpAddress,
|
||||||
tlsConfig,
|
tlsConfig,
|
||||||
)
|
)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("invalid SMTP TLS setting: %s", srv.appConfigService.DbConfig.SmtpTls.Value)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to connect to SMTP server: %w", err)
|
return nil, fmt.Errorf("failed to connect to SMTP server: %w", err)
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
UPDATE app_config_variables SET value = 'true' WHERE key = 'smtpTls';
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
UPDATE app_config_variables AS target
|
||||||
|
SET value = CASE
|
||||||
|
WHEN target.value = 'true' AND (SELECT value FROM app_config_variables WHERE key = 'smtpPort' LIMIT 1) = '587' THEN 'starttls'
|
||||||
|
WHEN target.value = 'true' THEN 'tls'
|
||||||
|
ELSE 'none'
|
||||||
|
END
|
||||||
|
WHERE target.key = 'smtpTls';
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
UPDATE app_config_variables SET value = 'true' WHERE key = 'smtpTls';
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
UPDATE app_config_variables
|
||||||
|
SET value = CASE
|
||||||
|
WHEN value = 'true' AND (SELECT value FROM app_config_variables WHERE key = 'smtpPort' LIMIT 1) = '587' THEN 'starttls'
|
||||||
|
WHEN value = 'true' THEN 'tls'
|
||||||
|
ELSE 'none'
|
||||||
|
END
|
||||||
|
WHERE key = 'smtpTls';
|
||||||
4
frontend/package-lock.json
generated
4
frontend/package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "pocket-id-frontend",
|
"name": "pocket-id-frontend",
|
||||||
"version": "0.30.0",
|
"version": "0.35.2",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "pocket-id-frontend",
|
"name": "pocket-id-frontend",
|
||||||
"version": "0.30.0",
|
"version": "0.35.2",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@simplewebauthn/browser": "^13.1.0",
|
"@simplewebauthn/browser": "^13.1.0",
|
||||||
"@tailwindcss/vite": "^4.0.0",
|
"@tailwindcss/vite": "^4.0.0",
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export type AllAppConfig = AppConfig & {
|
|||||||
smtpFrom: string;
|
smtpFrom: string;
|
||||||
smtpUser: string;
|
smtpUser: string;
|
||||||
smtpPassword: string;
|
smtpPassword: string;
|
||||||
smtpTls: boolean;
|
smtpTls: 'none' | 'starttls' | 'tls';
|
||||||
smtpSkipCertVerify: boolean;
|
smtpSkipCertVerify: boolean;
|
||||||
emailLoginNotificationEnabled: boolean;
|
emailLoginNotificationEnabled: boolean;
|
||||||
// LDAP
|
// LDAP
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { env } from '$env/dynamic/public';
|
import { env } from '$env/dynamic/public';
|
||||||
import CheckboxWithLabel from '$lib/components/form/checkbox-with-label.svelte';
|
|
||||||
import { openConfirmDialog } from '$lib/components/confirm-dialog';
|
import { openConfirmDialog } from '$lib/components/confirm-dialog';
|
||||||
|
import CheckboxWithLabel from '$lib/components/form/checkbox-with-label.svelte';
|
||||||
import FormInput from '$lib/components/form/form-input.svelte';
|
import FormInput from '$lib/components/form/form-input.svelte';
|
||||||
import { Button } from '$lib/components/ui/button';
|
import { Button } from '$lib/components/ui/button';
|
||||||
|
import Label from '$lib/components/ui/label/label.svelte';
|
||||||
|
import * as Select from '$lib/components/ui/select';
|
||||||
import AppConfigService from '$lib/services/app-config-service';
|
import AppConfigService from '$lib/services/app-config-service';
|
||||||
import type { AllAppConfig } from '$lib/types/application-configuration';
|
import type { AllAppConfig } from '$lib/types/application-configuration';
|
||||||
import { createForm } from '$lib/utils/form-util';
|
import { createForm } from '$lib/utils/form-util';
|
||||||
@@ -20,6 +22,11 @@
|
|||||||
|
|
||||||
const appConfigService = new AppConfigService();
|
const appConfigService = new AppConfigService();
|
||||||
const uiConfigDisabled = env.PUBLIC_UI_CONFIG_DISABLED === 'true';
|
const uiConfigDisabled = env.PUBLIC_UI_CONFIG_DISABLED === 'true';
|
||||||
|
const tlsOptions = {
|
||||||
|
none: 'None',
|
||||||
|
starttls: 'StartTLS',
|
||||||
|
tls: 'TLS'
|
||||||
|
};
|
||||||
|
|
||||||
let isSendingTestEmail = $state(false);
|
let isSendingTestEmail = $state(false);
|
||||||
|
|
||||||
@@ -29,7 +36,7 @@
|
|||||||
smtpUser: z.string(),
|
smtpUser: z.string(),
|
||||||
smtpPassword: z.string(),
|
smtpPassword: z.string(),
|
||||||
smtpFrom: z.string().email(),
|
smtpFrom: z.string().email(),
|
||||||
smtpTls: z.boolean(),
|
smtpTls: z.enum(['none', 'starttls', 'tls']),
|
||||||
smtpSkipCertVerify: z.boolean(),
|
smtpSkipCertVerify: z.boolean(),
|
||||||
emailOneTimeAccessEnabled: z.boolean(),
|
emailOneTimeAccessEnabled: z.boolean(),
|
||||||
emailLoginNotificationEnabled: z.boolean()
|
emailLoginNotificationEnabled: z.boolean()
|
||||||
@@ -96,12 +103,22 @@
|
|||||||
<FormInput label="SMTP User" bind:input={$inputs.smtpUser} />
|
<FormInput label="SMTP User" bind:input={$inputs.smtpUser} />
|
||||||
<FormInput label="SMTP Password" type="password" bind:input={$inputs.smtpPassword} />
|
<FormInput label="SMTP Password" type="password" bind:input={$inputs.smtpPassword} />
|
||||||
<FormInput label="SMTP From" bind:input={$inputs.smtpFrom} />
|
<FormInput label="SMTP From" bind:input={$inputs.smtpFrom} />
|
||||||
<CheckboxWithLabel
|
<div class="grid gap-2">
|
||||||
id="tls"
|
<Label class="mb-0" for="smtp-tls">SMTP TLS Option</Label>
|
||||||
label="TLS"
|
<Select.Root
|
||||||
description="Enable TLS for the SMTP connection."
|
selected={{ value: $inputs.smtpTls.value, label: tlsOptions[$inputs.smtpTls.value] }}
|
||||||
bind:checked={$inputs.smtpTls.value}
|
onSelectedChange={(v) => ($inputs.smtpTls.value = v!.value)}
|
||||||
/>
|
>
|
||||||
|
<Select.Trigger>
|
||||||
|
<Select.Value placeholder="Email TLS Option" />
|
||||||
|
</Select.Trigger>
|
||||||
|
<Select.Content>
|
||||||
|
<Select.Item value="none" label="None" />
|
||||||
|
<Select.Item value="starttls" label="StartTLS" />
|
||||||
|
<Select.Item value="tls" label="TLS" />
|
||||||
|
</Select.Content>
|
||||||
|
</Select.Root>
|
||||||
|
</div>
|
||||||
<CheckboxWithLabel
|
<CheckboxWithLabel
|
||||||
id="skip-cert-verify"
|
id="skip-cert-verify"
|
||||||
label="Skip Certificate Verification"
|
label="Skip Certificate Verification"
|
||||||
|
|||||||
Reference in New Issue
Block a user