Skip to content
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,22 @@ 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": ["*"],
"timeout_secs": 30
}
```

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
Expand Down
17 changes: 13 additions & 4 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
2 changes: 2 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
Expand Down