mirror of
https://github.com/nikdoof/pocket-id.git
synced 2025-12-14 15:22:18 +00:00
fix: send hostname derived from PUBLIC_APP_URL with SMTP EHLO command
This commit is contained in:
@@ -99,7 +99,7 @@ func SendEmail[V any](srv *EmailService, toEmail email.Address, template email.T
|
|||||||
smtpAddress := srv.appConfigService.DbConfig.SmtpHost.Value + ":" + port
|
smtpAddress := srv.appConfigService.DbConfig.SmtpHost.Value + ":" + port
|
||||||
var client *smtp.Client
|
var client *smtp.Client
|
||||||
if srv.appConfigService.DbConfig.SmtpTls.Value == "false" {
|
if srv.appConfigService.DbConfig.SmtpTls.Value == "false" {
|
||||||
client, err = smtp.Dial(smtpAddress)
|
client, err = srv.connectToSmtpServer(smtpAddress)
|
||||||
} else if port == "465" {
|
} else if port == "465" {
|
||||||
client, err = srv.connectToSmtpServerUsingImplicitTLS(
|
client, err = srv.connectToSmtpServerUsingImplicitTLS(
|
||||||
smtpAddress,
|
smtpAddress,
|
||||||
@@ -115,9 +115,12 @@ func SendEmail[V any](srv *EmailService, toEmail email.Address, template email.T
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to connect to SMTP server: %w", err)
|
return fmt.Errorf("failed to connect to SMTP server: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
defer client.Close()
|
defer client.Close()
|
||||||
|
|
||||||
|
if err := client.Hello(common.EnvConfig.Host); err != nil {
|
||||||
|
return fmt.Errorf("failed to say hello to SMTP server: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
smtpUser := srv.appConfigService.DbConfig.SmtpUser.Value
|
smtpUser := srv.appConfigService.DbConfig.SmtpUser.Value
|
||||||
smtpPassword := srv.appConfigService.DbConfig.SmtpPassword.Value
|
smtpPassword := srv.appConfigService.DbConfig.SmtpPassword.Value
|
||||||
|
|
||||||
@@ -141,6 +144,15 @@ func SendEmail[V any](srv *EmailService, toEmail email.Address, template email.T
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (srv *EmailService) connectToSmtpServer(serverAddr string) (*smtp.Client, error) {
|
||||||
|
conn, err := netDialer.Dial("tcp", serverAddr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to connect to SMTP server: %w", err)
|
||||||
|
}
|
||||||
|
client, err := smtp.NewClient(conn, srv.appConfigService.DbConfig.SmtpHost.Value)
|
||||||
|
return client, err
|
||||||
|
}
|
||||||
|
|
||||||
func (srv *EmailService) connectToSmtpServerUsingImplicitTLS(serverAddr string, tlsConfig *tls.Config) (*smtp.Client, error) {
|
func (srv *EmailService) connectToSmtpServerUsingImplicitTLS(serverAddr string, tlsConfig *tls.Config) (*smtp.Client, error) {
|
||||||
tlsDialer := &tls.Dialer{
|
tlsDialer := &tls.Dialer{
|
||||||
NetDialer: netDialer,
|
NetDialer: netDialer,
|
||||||
|
|||||||
Reference in New Issue
Block a user