From 1998052a0dd3625d3d728ae115b41677f4b42bb1 Mon Sep 17 00:00:00 2001 From: Bryan Frimin Date: Fri, 5 Jun 2026 07:27:36 +0200 Subject: [PATCH] Fall back to os.Hostname() when SMTP_HELLO_NAME is not set Using localhost as the EHLO identity is the Go net/smtp default but is rejected by strict relays such as Google Workspace. os.Hostname() is the conventional SMTP client fallback and returns the actual machine or pod name in production environments. Signed-off-by: Bryan Frimin --- pkg/mailer/mailer.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/mailer/mailer.go b/pkg/mailer/mailer.go index 0d0471bab..e4dad8c8b 100644 --- a/pkg/mailer/mailer.go +++ b/pkg/mailer/mailer.go @@ -22,6 +22,7 @@ import ( "fmt" "net" "net/smtp" + "os" "time" "github.com/jhillyerd/enmime" @@ -320,12 +321,17 @@ func (h *sendingHandler) sendMail(ctx context.Context, to []string, msg []byte) defer func() { _ = c.Quit() }() - if h.smtp.HelloName != "" { - if err := c.Hello(h.smtp.HelloName); err != nil { - return fmt.Errorf("SMTP EHLO error: %w", err) + helloName := h.smtp.HelloName + if helloName == "" { + if helloName, err = os.Hostname(); err != nil { + helloName = "localhost" } } + if err := c.Hello(helloName); err != nil { + return fmt.Errorf("SMTP EHLO error: %w", err) + } + if h.smtp.TLSRequired { if err := c.StartTLS(&tls.Config{ServerName: host}); err != nil { return fmt.Errorf("TLS negotiation error: %w", err)