From 7d74516270d5fce31a2a67f38b18a0e718ed90e9 Mon Sep 17 00:00:00 2001 From: Ralph Slooten Date: Tue, 26 Aug 2025 12:17:01 +1200 Subject: [PATCH] Fix: Move HELO/EHLO hostname setting to the correct position in SMTP client creation (#558) --- internal/smtpd/forward.go | 14 +++++++------- internal/smtpd/relay.go | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/internal/smtpd/forward.go b/internal/smtpd/forward.go index 98fe9cf..e439e3c 100644 --- a/internal/smtpd/forward.go +++ b/internal/smtpd/forward.go @@ -51,6 +51,13 @@ func createForwardingSMTPClient(config config.SMTPForwardConfigStruct, addr stri return nil, fmt.Errorf("error connecting to %s: %v", addr, err) } + // Set the hostname for HELO/EHLO + if hostname, err := os.Hostname(); err == nil { + if err := client.Hello(hostname); err != nil { + return nil, fmt.Errorf("error saying HELO/EHLO to %s: %v", addr, err) + } + } + if config.STARTTLS { tlsConf := &tls.Config{ServerName: config.Host} // #nosec tlsConf.InsecureSkipVerify = config.AllowInsecure @@ -61,13 +68,6 @@ func createForwardingSMTPClient(config config.SMTPForwardConfigStruct, addr stri } } - // Set the hostname for HELO/EHLO - if hostname, err := os.Hostname(); err == nil { - if err := client.Hello(hostname); err != nil { - return nil, fmt.Errorf("error saying HELO/EHLO to %s: %v", addr, err) - } - } - // Note: The caller is responsible for closing the client return client, nil } diff --git a/internal/smtpd/relay.go b/internal/smtpd/relay.go index 5e94b0a..c76e6a7 100644 --- a/internal/smtpd/relay.go +++ b/internal/smtpd/relay.go @@ -85,6 +85,13 @@ func createRelaySMTPClient(config config.SMTPRelayConfigStruct, addr string) (*s return nil, fmt.Errorf("error connecting to %s: %v", addr, err) } + // Set the hostname for HELO/EHLO + if hostname, err := os.Hostname(); err == nil { + if err := client.Hello(hostname); err != nil { + return nil, fmt.Errorf("error saying HELO/EHLO to %s: %v", addr, err) + } + } + if config.STARTTLS { tlsConf := &tls.Config{ServerName: config.Host} // #nosec tlsConf.InsecureSkipVerify = config.AllowInsecure @@ -95,13 +102,6 @@ func createRelaySMTPClient(config config.SMTPRelayConfigStruct, addr string) (*s } } - // Set the hostname for HELO/EHLO - if hostname, err := os.Hostname(); err == nil { - if err := client.Hello(hostname); err != nil { - return nil, fmt.Errorf("error saying HELO/EHLO to %s: %v", addr, err) - } - } - // Note: The caller is responsible for closing the client return client, nil }