Merge pull request #20 from niclan/master

Add support SMTP HELO
This commit is contained in:
Doug Lauder
2025-05-23 12:07:11 -04:00
committed by GitHub
4 changed files with 25 additions and 4 deletions

View File

@ -46,6 +46,7 @@ On local PC (192.168.1.54) create file `/etc/mailrelay.json` with contents:
"smtp_password": "secretAppPassword", "smtp_password": "secretAppPassword",
"smtp_max_email_size": 10485760, "smtp_max_email_size": 10485760,
"smtp_login_auth_type": false, "smtp_login_auth_type": false,
"smtp_helo": "smtp.example.com",
"local_listen_ip": "0.0.0.0", "local_listen_ip": "0.0.0.0",
"local_listen_port": 2525, "local_listen_port": 2525,
"allowed_hosts": ["*"], "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`, Run `mailrelay`,
```Bash ```Bash

View File

@ -92,21 +92,30 @@ func sendMail(e *mail.Envelope, config *relayConfig) error {
} }
func handshake(client *smtp.Client, config *relayConfig, tlsConfig *tls.Config) 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 config.STARTTLS {
if err := client.StartTLS(tlsConfig); err != nil { if err := client.StartTLS(tlsConfig); err != nil {
return errors.Wrap(err, "starttls error") return errors.Wrap(err, "starttls error")
} }
} }
var auth smtp.Auth var auth smtp.Auth = nil
if config.LoginAuthType { if config.LoginAuthType {
auth = LoginAuth(config.Username, config.Password) auth = LoginAuth(config.Username, config.Password)
} else { } else if config.Username != "" {
auth = smtp.PlainAuth("", config.Username, config.Password, config.Server) auth = smtp.PlainAuth("", config.Username, config.Password, config.Server)
} }
if err := client.Auth(auth); err != nil { if auth != nil {
return errors.Wrap(err, "auth error") if err := client.Auth(auth); err != nil {
return errors.Wrap(err, "auth error")
}
} }
return nil return nil
} }

View File

@ -30,6 +30,7 @@ type mailRelayConfig struct {
SMTPLoginAuthType bool `json:"smtp_login_auth_type"` SMTPLoginAuthType bool `json:"smtp_login_auth_type"`
SMTPUsername string `json:"smtp_username"` SMTPUsername string `json:"smtp_username"`
SMTPPassword string `json:"smtp_password"` SMTPPassword string `json:"smtp_password"`
SMTPHelo string `json:"smtp_helo"`
SkipCertVerify bool `json:"smtp_skip_cert_verify"` SkipCertVerify bool `json:"smtp_skip_cert_verify"`
MaxEmailSize int64 `json:"smtp_max_email_size"` MaxEmailSize int64 `json:"smtp_max_email_size"`
LocalListenIP string `json:"local_listen_ip"` LocalListenIP string `json:"local_listen_ip"`

View File

@ -47,6 +47,7 @@ func Start(appConfig *mailRelayConfig, verbose bool) (err error) {
"smtp_starttls": appConfig.SMTPStartTLS, "smtp_starttls": appConfig.SMTPStartTLS,
"smtp_login_auth_type": appConfig.SMTPLoginAuthType, "smtp_login_auth_type": appConfig.SMTPLoginAuthType,
"smtp_skip_cert_verify": appConfig.SkipCertVerify, "smtp_skip_cert_verify": appConfig.SkipCertVerify,
"smtp_helo": appConfig.SMTPHelo,
} }
cfg.BackendConfig = bcfg cfg.BackendConfig = bcfg
@ -64,6 +65,7 @@ type relayConfig struct {
Username string `json:"smtp_username"` Username string `json:"smtp_username"`
Password string `json:"smtp_password"` Password string `json:"smtp_password"`
SkipVerify bool `json:"smtp_skip_cert_verify"` SkipVerify bool `json:"smtp_skip_cert_verify"`
HeloHost string `json:"smtp_helo"`
} }
// mailRelayProcessor decorator relays emails to another SMTP server. // mailRelayProcessor decorator relays emails to another SMTP server.