mirror of
https://github.com/nikdoof/pocket-id.git
synced 2025-12-14 07:12:19 +00:00
feat: add option to disable TLS for email sending
This commit is contained in:
@@ -22,5 +22,6 @@ 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"`
|
||||||
SmtpSkipCertVerify string `json:"smtpSkipCertVerify"`
|
SmtpSkipCertVerify string `json:"smtpSkipCertVerify"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,5 +25,6 @@ type AppConfig struct {
|
|||||||
SmtpFrom AppConfigVariable
|
SmtpFrom AppConfigVariable
|
||||||
SmtpUser AppConfigVariable
|
SmtpUser AppConfigVariable
|
||||||
SmtpPassword AppConfigVariable
|
SmtpPassword AppConfigVariable
|
||||||
|
SmtpTls AppConfigVariable
|
||||||
SmtpSkipCertVerify AppConfigVariable
|
SmtpSkipCertVerify AppConfigVariable
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,6 +95,11 @@ var defaultDbConfig = model.AppConfig{
|
|||||||
Key: "smtpPassword",
|
Key: "smtpPassword",
|
||||||
Type: "string",
|
Type: "string",
|
||||||
},
|
},
|
||||||
|
SmtpTls: model.AppConfigVariable{
|
||||||
|
Key: "smtpTls",
|
||||||
|
Type: "bool",
|
||||||
|
DefaultValue: "true",
|
||||||
|
},
|
||||||
SmtpSkipCertVerify: model.AppConfigVariable{
|
SmtpSkipCertVerify: model.AppConfigVariable{
|
||||||
Key: "smtpSkipCertVerify",
|
Key: "smtpSkipCertVerify",
|
||||||
Type: "bool",
|
Type: "bool",
|
||||||
|
|||||||
@@ -98,15 +98,18 @@ func SendEmail[V any](srv *EmailService, toEmail email.Address, template email.T
|
|||||||
|
|
||||||
// Connect to the SMTP server
|
// Connect to the SMTP server
|
||||||
port := srv.appConfigService.DbConfig.SmtpPort.Value
|
port := srv.appConfigService.DbConfig.SmtpPort.Value
|
||||||
|
smtpAddress := srv.appConfigService.DbConfig.SmtpHost.Value + ":" + port
|
||||||
var client *smtp.Client
|
var client *smtp.Client
|
||||||
if port == "465" {
|
if srv.appConfigService.DbConfig.SmtpTls.Value == "false" {
|
||||||
|
client, err = smtp.Dial(smtpAddress)
|
||||||
|
} else if port == "465" {
|
||||||
client, err = srv.connectToSmtpServerUsingImplicitTLS(
|
client, err = srv.connectToSmtpServerUsingImplicitTLS(
|
||||||
srv.appConfigService.DbConfig.SmtpHost.Value+":"+port,
|
smtpAddress,
|
||||||
tlsConfig,
|
tlsConfig,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
client, err = srv.connectToSmtpServerUsingStartTLS(
|
client, err = srv.connectToSmtpServerUsingStartTLS(
|
||||||
srv.appConfigService.DbConfig.SmtpHost.Value+":"+port,
|
smtpAddress,
|
||||||
tlsConfig,
|
tlsConfig,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ export type AllAppConfig = AppConfig & {
|
|||||||
smtpFrom: string;
|
smtpFrom: string;
|
||||||
smtpUser: string;
|
smtpUser: string;
|
||||||
smtpPassword: string;
|
smtpPassword: string;
|
||||||
|
smtpTls: boolean;
|
||||||
smtpSkipCertVerify: boolean;
|
smtpSkipCertVerify: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
smtpUser: appConfig.smtpUser,
|
smtpUser: appConfig.smtpUser,
|
||||||
smtpPassword: appConfig.smtpPassword,
|
smtpPassword: appConfig.smtpPassword,
|
||||||
smtpFrom: appConfig.smtpFrom,
|
smtpFrom: appConfig.smtpFrom,
|
||||||
|
smtpTls: appConfig.smtpTls,
|
||||||
smtpSkipCertVerify: appConfig.smtpSkipCertVerify
|
smtpSkipCertVerify: appConfig.smtpSkipCertVerify
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -37,6 +38,7 @@
|
|||||||
smtpUser: z.string().min(1),
|
smtpUser: z.string().min(1),
|
||||||
smtpPassword: z.string().min(1),
|
smtpPassword: z.string().min(1),
|
||||||
smtpFrom: z.string().email(),
|
smtpFrom: z.string().email(),
|
||||||
|
smtpTls: z.boolean(),
|
||||||
smtpSkipCertVerify: z.boolean()
|
smtpSkipCertVerify: z.boolean()
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -79,12 +81,18 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<form onsubmit={onSubmit}>
|
<form onsubmit={onSubmit}>
|
||||||
<div class="mt-5 grid grid-cols-1 gap-5 md:grid-cols-2">
|
<div class="mt-5 grid grid-cols-1 gap-5 md:grid-cols-2 items-start">
|
||||||
<FormInput label="SMTP Host" bind:input={$inputs.smtpHost} />
|
<FormInput label="SMTP Host" bind:input={$inputs.smtpHost} />
|
||||||
<FormInput label="SMTP Port" type="number" bind:input={$inputs.smtpPort} />
|
<FormInput label="SMTP Port" type="number" bind:input={$inputs.smtpPort} />
|
||||||
<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
|
||||||
|
id="tls"
|
||||||
|
label="TLS"
|
||||||
|
description="Enable TLS for the SMTP connection."
|
||||||
|
bind:checked={$inputs.smtpTls.value}
|
||||||
|
/>
|
||||||
<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