mirror of
https://github.com/wiggin77/mailrelay.git
synced 2025-08-17 18:41:05 +02:00
@@ -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
|
||||
|
13
client.go
13
client.go
@@ -92,22 +92,31 @@ 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 auth != nil {
|
||||
if err := client.Auth(auth); err != nil {
|
||||
return errors.Wrap(err, "auth error")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
1
main.go
1
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"`
|
||||
|
@@ -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.
|
||||
|
Reference in New Issue
Block a user