mirror of
https://github.com/wiggin77/mailrelay.git
synced 2024-11-27 01:23:10 +01:00
max email size; connection timeout
This commit is contained in:
parent
066613c962
commit
eaa5e32600
@ -44,10 +44,12 @@ On local PC (192.168.1.54) create file `/etc/mailrelay.json` with contents:
|
|||||||
"smtp_starttls": false,
|
"smtp_starttls": false,
|
||||||
"smtp_username": "username@fastmail.com",
|
"smtp_username": "username@fastmail.com",
|
||||||
"smtp_password": "secretAppPassword",
|
"smtp_password": "secretAppPassword",
|
||||||
|
"smtp_max_email_size": 10485760,
|
||||||
"smtp_login_auth_type": false,
|
"smtp_login_auth_type": false,
|
||||||
"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": ["*"],
|
||||||
|
"timeout_secs": 30
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -4,9 +4,11 @@
|
|||||||
"smtp_starttls": false,
|
"smtp_starttls": false,
|
||||||
"smtp_login_auth_type": false,
|
"smtp_login_auth_type": false,
|
||||||
"smtp_username": "username@fastmail.com",
|
"smtp_username": "username@fastmail.com",
|
||||||
"smtp_password": "secret_app_password",
|
"smtp_password": "secret_app_password",
|
||||||
|
"smtp_max_email_size": 83886080,
|
||||||
"smtp_skip_cert_verify": false,
|
"smtp_skip_cert_verify": false,
|
||||||
"local_listen_port": 2525,
|
"local_listen_port": 2525,
|
||||||
"local_listen_ip": "0.0.0.0",
|
"local_listen_ip": "0.0.0.0",
|
||||||
"allowed_hosts": ["*"]
|
"allowed_hosts": ["*"],
|
||||||
|
"timeout_secs": 30
|
||||||
}
|
}
|
||||||
|
24
main.go
24
main.go
@ -12,6 +12,14 @@ import (
|
|||||||
log "github.com/flashmob/go-guerrilla/log"
|
log "github.com/flashmob/go-guerrilla/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
DefaultSTMPPort = 465
|
||||||
|
DefaultMaxEmailSize = (10 << 23) // 83 MB
|
||||||
|
DefaultLocalListenIP = "0.0.0.0"
|
||||||
|
DefaultLocalListenPort = 2525
|
||||||
|
DefaultTimeoutSecs = 300 // 5 minutes
|
||||||
|
)
|
||||||
|
|
||||||
// Logger is the global logger
|
// Logger is the global logger
|
||||||
var Logger log.Logger
|
var Logger log.Logger
|
||||||
|
|
||||||
@ -23,9 +31,11 @@ type mailRelayConfig struct {
|
|||||||
SMTPUsername string `json:"smtp_username"`
|
SMTPUsername string `json:"smtp_username"`
|
||||||
SMTPPassword string `json:"smtp_password"`
|
SMTPPassword string `json:"smtp_password"`
|
||||||
SkipCertVerify bool `json:"smtp_skip_cert_verify"`
|
SkipCertVerify bool `json:"smtp_skip_cert_verify"`
|
||||||
|
MaxEmailSize int64 `json:"smtp_max_email_size"`
|
||||||
LocalListenIP string `json:"local_listen_ip"`
|
LocalListenIP string `json:"local_listen_ip"`
|
||||||
LocalListenPort int `json:"local_listen_port"`
|
LocalListenPort int `json:"local_listen_port"`
|
||||||
AllowedHosts []string `json:"allowed_hosts"`
|
AllowedHosts []string `json:"allowed_hosts"`
|
||||||
|
TimeoutSecs int `json:"timeout_secs"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -90,6 +100,8 @@ func run() error {
|
|||||||
|
|
||||||
func loadConfig(path string) (*mailRelayConfig, error) {
|
func loadConfig(path string) (*mailRelayConfig, error) {
|
||||||
var cfg mailRelayConfig
|
var cfg mailRelayConfig
|
||||||
|
configDefaults(&cfg)
|
||||||
|
|
||||||
file, err := os.Open(path)
|
file, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -103,6 +115,18 @@ func loadConfig(path string) (*mailRelayConfig, error) {
|
|||||||
return &cfg, nil
|
return &cfg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func configDefaults(config *mailRelayConfig) {
|
||||||
|
config.SMTPPort = DefaultSTMPPort
|
||||||
|
config.SMTPStartTLS = false
|
||||||
|
config.SMTPLoginAuthType = false
|
||||||
|
config.MaxEmailSize = DefaultMaxEmailSize
|
||||||
|
config.SkipCertVerify = false
|
||||||
|
config.LocalListenIP = DefaultLocalListenIP
|
||||||
|
config.LocalListenPort = DefaultLocalListenPort
|
||||||
|
config.AllowedHosts = []string{"*"}
|
||||||
|
config.TimeoutSecs = DefaultTimeoutSecs
|
||||||
|
}
|
||||||
|
|
||||||
// sendTest sends a test message to the SMTP server specified in mailrelay.json
|
// sendTest sends a test message to the SMTP server specified in mailrelay.json
|
||||||
func sendTest(sender string, rcpt string, port int) error {
|
func sendTest(sender string, rcpt string, port int) error {
|
||||||
conn, err := smtp.Dial(fmt.Sprintf("localhost:%d", port))
|
conn, err := smtp.Dial(fmt.Sprintf("localhost:%d", port))
|
||||||
|
@ -9,7 +9,9 @@ import (
|
|||||||
"github.com/flashmob/go-guerrilla/mail"
|
"github.com/flashmob/go-guerrilla/mail"
|
||||||
)
|
)
|
||||||
|
|
||||||
const saveWorkersSize = 3
|
const (
|
||||||
|
saveWorkersSize = 3
|
||||||
|
)
|
||||||
|
|
||||||
// Start starts the server.
|
// Start starts the server.
|
||||||
func Start(appConfig *mailRelayConfig, verbose bool) (err error) {
|
func Start(appConfig *mailRelayConfig, verbose bool) (err error) {
|
||||||
@ -28,6 +30,8 @@ func Start(appConfig *mailRelayConfig, verbose bool) (err error) {
|
|||||||
sc := guerrilla.ServerConfig{
|
sc := guerrilla.ServerConfig{
|
||||||
ListenInterface: listen,
|
ListenInterface: listen,
|
||||||
IsEnabled: true,
|
IsEnabled: true,
|
||||||
|
MaxSize: appConfig.MaxEmailSize,
|
||||||
|
Timeout: appConfig.TimeoutSecs,
|
||||||
}
|
}
|
||||||
cfg.Servers = append(cfg.Servers, sc)
|
cfg.Servers = append(cfg.Servers, sc)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user