feat: add option to disable TLS for email sending

This commit is contained in:
Elias Schneider
2024-11-28 12:13:23 +01:00
parent 7d6b1d19e9
commit f9fa2c6706
6 changed files with 23 additions and 4 deletions

View File

@@ -95,6 +95,11 @@ var defaultDbConfig = model.AppConfig{
Key: "smtpPassword",
Type: "string",
},
SmtpTls: model.AppConfigVariable{
Key: "smtpTls",
Type: "bool",
DefaultValue: "true",
},
SmtpSkipCertVerify: model.AppConfigVariable{
Key: "smtpSkipCertVerify",
Type: "bool",

View File

@@ -98,15 +98,18 @@ func SendEmail[V any](srv *EmailService, toEmail email.Address, template email.T
// Connect to the SMTP server
port := srv.appConfigService.DbConfig.SmtpPort.Value
smtpAddress := srv.appConfigService.DbConfig.SmtpHost.Value + ":" + port
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(
srv.appConfigService.DbConfig.SmtpHost.Value+":"+port,
smtpAddress,
tlsConfig,
)
} else {
client, err = srv.connectToSmtpServerUsingStartTLS(
srv.appConfigService.DbConfig.SmtpHost.Value+":"+port,
smtpAddress,
tlsConfig,
)
}