From 846e3b9a372c124c553aeb6858e8d650dffaa95a Mon Sep 17 00:00:00 2001 From: Nicolai Langfeldt Date: Thu, 24 Apr 2025 11:17:35 +0200 Subject: [PATCH 01/18] Support HELO --- client.go | 13 +++++++++++++ server.go | 1 + 2 files changed, 14 insertions(+) diff --git a/client.go b/client.go index 5579a1c..3605e6d 100644 --- a/client.go +++ b/client.go @@ -92,12 +92,25 @@ func sendMail(e *mail.Envelope, config *relayConfig) error { } func handshake(client *smtp.Client, config *relayConfig, tlsConfig *tls.Config) error { + if config.HeloHost != "" { + if err := client.Hello(config.HeloHost); err != nil { + return errors.Wrap(err, "HELO error") + } + } + if config.STARTTLS { if err := client.StartTLS(tlsConfig); err != nil { return errors.Wrap(err, "starttls error") } + // Re-HELO after STARTTLS + if config.HeloHost != "" { + if err := client.Hello(config.HeloHost); err != nil { + return errors.Wrap(err, "HELO error") + } + } } + var auth smtp.Auth if config.LoginAuthType { auth = LoginAuth(config.Username, config.Password) diff --git a/server.go b/server.go index cd9994f..96bc218 100644 --- a/server.go +++ b/server.go @@ -64,6 +64,7 @@ type relayConfig struct { Username string `json:"smtp_username"` Password string `json:"smtp_password"` SkipVerify bool `json:"smtp_skip_cert_verify"` + HeloHost string `json:"smtp_helo"` } // mailRelayProcessor decorator relays emails to another SMTP server. From 4499cfa72162fb53088c4a19a14bd087b0d47b95 Mon Sep 17 00:00:00 2001 From: Nicolai Langfeldt Date: Thu, 24 Apr 2025 11:39:05 +0200 Subject: [PATCH 02/18] Replace in go.mod --- go.mod | 2 ++ 1 file changed, 2 insertions(+) diff --git a/go.mod b/go.mod index f926007..8a2812f 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,7 @@ +replace github.com/wiggin77/mailrelay => github.com/niclan/mailrelay module github.com/wiggin77/mailrelay + go 1.14 require ( From 3a543f98f0e28d5a77011abd7fec989ee7871c2d Mon Sep 17 00:00:00 2001 From: Nicolai Langfeldt Date: Thu, 24 Apr 2025 11:41:01 +0200 Subject: [PATCH 03/18] Replace wasn't enough --- go.mod | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 8a2812f..0d5cc96 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,6 @@ replace github.com/wiggin77/mailrelay => github.com/niclan/mailrelay -module github.com/wiggin77/mailrelay +module github.com/niclan/mailrelay +# module github.com/wiggin77/mailrelay go 1.14 From 3da9e780ed845707d3b60565e7ff75e30188d776 Mon Sep 17 00:00:00 2001 From: Nicolai Langfeldt Date: Thu, 24 Apr 2025 11:43:07 +0200 Subject: [PATCH 04/18] Better comment character --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 0d5cc96..90a07cd 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ replace github.com/wiggin77/mailrelay => github.com/niclan/mailrelay module github.com/niclan/mailrelay -# module github.com/wiggin77/mailrelay +// module github.com/wiggin77/mailrelay go 1.14 From 095847db1d7bf1ff954babc2c1397c5acb340fb6 Mon Sep 17 00:00:00 2001 From: Nicolai Langfeldt Date: Thu, 24 Apr 2025 12:38:25 +0200 Subject: [PATCH 05/18] Re-HELO has no function for us --- client.go | 6 ------ go.mod | 2 -- 2 files changed, 8 deletions(-) diff --git a/client.go b/client.go index 3605e6d..e10adf9 100644 --- a/client.go +++ b/client.go @@ -102,12 +102,6 @@ func handshake(client *smtp.Client, config *relayConfig, tlsConfig *tls.Config) if err := client.StartTLS(tlsConfig); err != nil { return errors.Wrap(err, "starttls error") } - // Re-HELO after STARTTLS - if config.HeloHost != "" { - if err := client.Hello(config.HeloHost); err != nil { - return errors.Wrap(err, "HELO error") - } - } } diff --git a/go.mod b/go.mod index 90a07cd..e3f207f 100644 --- a/go.mod +++ b/go.mod @@ -1,7 +1,5 @@ replace github.com/wiggin77/mailrelay => github.com/niclan/mailrelay module github.com/niclan/mailrelay -// module github.com/wiggin77/mailrelay - go 1.14 From 59d3525f018eee7aff07dbe0eaf03d447a6b8d98 Mon Sep 17 00:00:00 2001 From: Nicolai Langfeldt Date: Thu, 24 Apr 2025 12:40:15 +0200 Subject: [PATCH 06/18] Tag on "master" for replace --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index e3f207f..dee284f 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -replace github.com/wiggin77/mailrelay => github.com/niclan/mailrelay +replace github.com/wiggin77/mailrelay => github.com/niclan/mailrelay master module github.com/niclan/mailrelay go 1.14 From c4c5bc7dc63df0153bc802d2f2239fd67f368810 Mon Sep 17 00:00:00 2001 From: Nicolai Langfeldt Date: Thu, 24 Apr 2025 12:40:53 +0200 Subject: [PATCH 07/18] How about @master? --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index dee284f..7a2b4c2 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -replace github.com/wiggin77/mailrelay => github.com/niclan/mailrelay master +replace github.com/wiggin77/mailrelay => github.com/niclan/mailrelay@master module github.com/niclan/mailrelay go 1.14 From 7a214ef109b2ff6abd376ea519aff837d10a6ff3 Mon Sep 17 00:00:00 2001 From: Nicolai Langfeldt Date: Thu, 24 Apr 2025 12:47:28 +0200 Subject: [PATCH 08/18] Give up on replace --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 7a2b4c2..71df9b9 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -replace github.com/wiggin77/mailrelay => github.com/niclan/mailrelay@master +// module github.com/wiggin77/mailrelay@v1.04 module github.com/niclan/mailrelay go 1.14 From f084a0a236268f1f2c8bb80b3e519b574ed35c16 Mon Sep 17 00:00:00 2001 From: Nicolai Langfeldt Date: Thu, 24 Apr 2025 12:48:23 +0200 Subject: [PATCH 09/18] WTF --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 71df9b9..09b2782 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,5 @@ // module github.com/wiggin77/mailrelay@v1.04 -module github.com/niclan/mailrelay +module github.com/niclan/mailrelay@master go 1.14 From 7279a4ff7172b90e607f1454d51113dd8da80d9e Mon Sep 17 00:00:00 2001 From: Nicolai Langfeldt Date: Thu, 24 Apr 2025 12:50:09 +0200 Subject: [PATCH 10/18] Randomly flailing --- go.mod | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 go.mod diff --git a/go.mod b/go.mod deleted file mode 100644 index 09b2782..0000000 --- a/go.mod +++ /dev/null @@ -1,18 +0,0 @@ -// module github.com/wiggin77/mailrelay@v1.04 -module github.com/niclan/mailrelay@master - -go 1.14 - -require ( - github.com/asaskevich/EventBus v0.0.0-20180103000110-68a521d7cbbb // indirect - github.com/flashmob/go-guerrilla v1.6.1 - github.com/go-sql-driver/mysql v1.5.0 // indirect - github.com/kr/text v0.2.0 // indirect - github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect - github.com/pkg/errors v0.9.1 - github.com/sirupsen/logrus v1.6.0 // indirect - github.com/stretchr/testify v1.5.1 // indirect - golang.org/x/sys v0.1.0 // indirect - gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect - gopkg.in/yaml.v2 v2.3.0 // indirect -) From 5d8c9cef9acd018cb27133e1e2bdf191a13d26d5 Mon Sep 17 00:00:00 2001 From: Nicolai Langfeldt Date: Fri, 25 Apr 2025 12:32:13 +0200 Subject: [PATCH 11/18] Make smtp_hello in config understood --- README.md | 1 + main.go | 1 + server.go | 1 + 3 files changed, 3 insertions(+) diff --git a/README.md b/README.md index 0408fd9..a9c03ca 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,7 @@ On local PC (192.168.1.54) create file `/etc/mailrelay.json` with contents: "smtp_password": "secretAppPassword", "smtp_max_email_size": 10485760, "smtp_login_auth_type": false, + "smtp_helo": "smtp.example.com", "local_listen_ip": "0.0.0.0", "local_listen_port": 2525, "allowed_hosts": ["*"], diff --git a/main.go b/main.go index d2939a6..893a93d 100644 --- a/main.go +++ b/main.go @@ -30,6 +30,7 @@ type mailRelayConfig struct { SMTPLoginAuthType bool `json:"smtp_login_auth_type"` SMTPUsername string `json:"smtp_username"` SMTPPassword string `json:"smtp_password"` + SMTPHelo string `json:"smtp_helo"` SkipCertVerify bool `json:"smtp_skip_cert_verify"` MaxEmailSize int64 `json:"smtp_max_email_size"` LocalListenIP string `json:"local_listen_ip"` diff --git a/server.go b/server.go index 96bc218..891156e 100644 --- a/server.go +++ b/server.go @@ -47,6 +47,7 @@ func Start(appConfig *mailRelayConfig, verbose bool) (err error) { "smtp_starttls": appConfig.SMTPStartTLS, "smtp_login_auth_type": appConfig.SMTPLoginAuthType, "smtp_skip_cert_verify": appConfig.SkipCertVerify, + "smtp_helo": appConfig.SMTPHelo, } cfg.BackendConfig = bcfg From 118f7b698f506a568c2528df3c0c4133b53f7d8c Mon Sep 17 00:00:00 2001 From: Nicolai Langfeldt Date: Fri, 25 Apr 2025 12:48:59 +0200 Subject: [PATCH 12/18] Do not auth unless we have something to auth with --- client.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client.go b/client.go index e10adf9..4c9ff8f 100644 --- a/client.go +++ b/client.go @@ -105,14 +105,14 @@ func handshake(client *smtp.Client, config *relayConfig, tlsConfig *tls.Config) } - var auth smtp.Auth + var auth smtp.Auth = nil if config.LoginAuthType { auth = LoginAuth(config.Username, config.Password) - } else { + } else if config.Username != "" { auth = smtp.PlainAuth("", config.Username, config.Password, config.Server) } - if err := client.Auth(auth); err != nil { + if auth != nil && err := client.Auth(auth); err != nil { return errors.Wrap(err, "auth error") } return nil From 53babef950bf9980f3172fb892ed288f50bf4691 Mon Sep 17 00:00:00 2001 From: Nicolai Langfeldt Date: Fri, 25 Apr 2025 12:58:32 +0200 Subject: [PATCH 13/18] Make correct --- client.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/client.go b/client.go index 4c9ff8f..1976507 100644 --- a/client.go +++ b/client.go @@ -112,8 +112,10 @@ func handshake(client *smtp.Client, config *relayConfig, tlsConfig *tls.Config) auth = smtp.PlainAuth("", config.Username, config.Password, config.Server) } - if auth != nil && err := client.Auth(auth); err != nil { - return errors.Wrap(err, "auth error") + if auth != nil { + if err := client.Auth(auth); err != nil { + return errors.Wrap(err, "auth error") + } } return nil } From 90e27fd8f6d6d8ff7b920078b09e97a264eba93a Mon Sep 17 00:00:00 2001 From: Nicolai Langfeldt Date: Fri, 25 Apr 2025 13:23:13 +0200 Subject: [PATCH 14/18] Document changes more --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index a9c03ca..4046dba 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,14 @@ On local PC (192.168.1.54) create file `/etc/mailrelay.json` with contents: } ``` +Notes on the configuration: + +- `smtp_helo` is optional - when given the client will present itself + to the upstream with the given name. +- `smtp_username` is optional - if given the client will attempt to + authenticate itself with she server. You should also give a password + in this case. + Run `mailrelay`, ```Bash From be3ec48813f265a88f02dece2ceca0413982e618 Mon Sep 17 00:00:00 2001 From: Nicolai Langfeldt Date: Fri, 25 Apr 2025 13:25:12 +0200 Subject: [PATCH 15/18] Revert "Randomly flailing" This reverts commit 7279a4ff7172b90e607f1454d51113dd8da80d9e. --- go.mod | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 go.mod diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..09b2782 --- /dev/null +++ b/go.mod @@ -0,0 +1,18 @@ +// module github.com/wiggin77/mailrelay@v1.04 +module github.com/niclan/mailrelay@master + +go 1.14 + +require ( + github.com/asaskevich/EventBus v0.0.0-20180103000110-68a521d7cbbb // indirect + github.com/flashmob/go-guerrilla v1.6.1 + github.com/go-sql-driver/mysql v1.5.0 // indirect + github.com/kr/text v0.2.0 // indirect + github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect + github.com/pkg/errors v0.9.1 + github.com/sirupsen/logrus v1.6.0 // indirect + github.com/stretchr/testify v1.5.1 // indirect + golang.org/x/sys v0.1.0 // indirect + gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect + gopkg.in/yaml.v2 v2.3.0 // indirect +) From 6d85d463c48609231c9ca62e403cb0458cabd469 Mon Sep 17 00:00:00 2001 From: Nicolai Langfeldt Date: Fri, 25 Apr 2025 13:26:11 +0200 Subject: [PATCH 16/18] Restore upstream go.mod --- go.mod | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 09b2782..322de1d 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,4 @@ -// module github.com/wiggin77/mailrelay@v1.04 -module github.com/niclan/mailrelay@master +module github.com/wiggin77/mailrelay@v1.04 go 1.14 From 836bddeca8d6e93923143f445e07c21dbbd10112 Mon Sep 17 00:00:00 2001 From: Nicolai Langfeldt Date: Fri, 25 Apr 2025 13:27:50 +0200 Subject: [PATCH 17/18] Minimize PR --- client.go | 2 +- go.mod | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client.go b/client.go index 1976507..6514f3f 100644 --- a/client.go +++ b/client.go @@ -104,8 +104,8 @@ func handshake(client *smtp.Client, config *relayConfig, tlsConfig *tls.Config) } } - var auth smtp.Auth = nil + if config.LoginAuthType { auth = LoginAuth(config.Username, config.Password) } else if config.Username != "" { diff --git a/go.mod b/go.mod index 322de1d..f926007 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/wiggin77/mailrelay@v1.04 +module github.com/wiggin77/mailrelay go 1.14 From b6d0d7da961a1242192f43849e4109c46b1a0b93 Mon Sep 17 00:00:00 2001 From: Nicolai Langfeldt Date: Thu, 22 May 2025 23:31:27 +0200 Subject: [PATCH 18/18] Update README.md Fix typo s/she/the/ --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4046dba..42afc2d 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ Notes on the configuration: - `smtp_helo` is optional - when given the client will present itself to the upstream with the given name. - `smtp_username` is optional - if given the client will attempt to - authenticate itself with she server. You should also give a password + authenticate itself with the server. You should also give a password in this case. Run `mailrelay`,