mirror of
https://github.com/decke/smtprelay.git
synced 2025-12-25 16:52:29 -07:00
Support .env files if it exists
This commit is contained in:
@@ -22,7 +22,7 @@ device which produces mail.
|
||||
|
||||
## Main features
|
||||
|
||||
* Simple configuration with ini file or environment variables
|
||||
* Simple configuration with ini file .env file or environment variables
|
||||
* Supports SMTPS/TLS (465), STARTTLS (587) and unencrypted SMTP (25)
|
||||
* Checks for sender, receiver, client IP
|
||||
* Authentication support with file (LOGIN, PLAIN)
|
||||
|
||||
14
config.go
14
config.go
@@ -194,7 +194,18 @@ func setupTimeouts() {
|
||||
}
|
||||
|
||||
func ConfigLoad() {
|
||||
// configuration parsing
|
||||
// use .env file if it exists
|
||||
if _, err := os.Stat(".env"); err == nil {
|
||||
if err := ff.Parse(flagset, os.Args[1:],
|
||||
ff.WithEnvVarPrefix("smtprelay"),
|
||||
ff.WithConfigFile(".env"),
|
||||
ff.WithConfigFileParser(ff.EnvParser),
|
||||
); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
} else {
|
||||
// use env variables and smtprelay.ini file
|
||||
if err := ff.Parse(flagset, os.Args[1:],
|
||||
ff.WithEnvVarPrefix("smtprelay"),
|
||||
ff.WithConfigFileFlag("config"),
|
||||
@@ -203,6 +214,7 @@ func ConfigLoad() {
|
||||
fmt.Fprintf(os.Stderr, "error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
// Set up logging as soon as possible
|
||||
setupLogger()
|
||||
|
||||
Reference in New Issue
Block a user