fix: use OS hostname for SMTP EHLO message

This commit is contained in:
Elias Schneider
2025-01-24 10:36:16 +01:00
parent 2884021055
commit 47c39f6d38

View File

@@ -14,6 +14,7 @@ import (
"net" "net"
"net/smtp" "net/smtp"
"net/textproto" "net/textproto"
"os"
ttemplate "text/template" ttemplate "text/template"
"time" "time"
) )
@@ -117,8 +118,12 @@ func SendEmail[V any](srv *EmailService, toEmail email.Address, template email.T
} }
defer client.Close() defer client.Close()
if err := client.Hello(common.EnvConfig.Host); err != nil { // Set the hello message manually as for example Google rejects the default "localhost" value
return fmt.Errorf("failed to say hello to SMTP server: %w", err) hostname, err := os.Hostname()
if err == nil {
if err := client.Hello(hostname); 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