diff --git a/README.md b/README.md index 0408fd9..42afc2d 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": ["*"], @@ -53,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 the server. You should also give a password + in this case. + Run `mailrelay`, ```Bash diff --git a/client.go b/client.go index 5579a1c..6514f3f 100644 --- a/client.go +++ b/client.go @@ -92,21 +92,30 @@ 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") } } - 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 { - return errors.Wrap(err, "auth error") + if auth != nil { + if err := client.Auth(auth); err != nil { + return errors.Wrap(err, "auth error") + } } return nil } 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 cd9994f..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 @@ -64,6 +65,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.