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
|
## 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)
|
* Supports SMTPS/TLS (465), STARTTLS (587) and unencrypted SMTP (25)
|
||||||
* Checks for sender, receiver, client IP
|
* Checks for sender, receiver, client IP
|
||||||
* Authentication support with file (LOGIN, PLAIN)
|
* Authentication support with file (LOGIN, PLAIN)
|
||||||
|
|||||||
32
config.go
32
config.go
@@ -47,8 +47,8 @@ var (
|
|||||||
remotesStr = flagset.String("remotes", "", "Outgoing SMTP servers")
|
remotesStr = flagset.String("remotes", "", "Outgoing SMTP servers")
|
||||||
|
|
||||||
// additional flags
|
// additional flags
|
||||||
_ = flagset.String("config", "", "Path to config file (ini format)")
|
_ = flagset.String("config", "", "Path to config file (ini format)")
|
||||||
versionInfo = flagset.Bool("version", false, "Show version information")
|
versionInfo = flagset.Bool("version", false, "Show version information")
|
||||||
|
|
||||||
// internal
|
// internal
|
||||||
listenAddrs = []protoAddr{}
|
listenAddrs = []protoAddr{}
|
||||||
@@ -194,14 +194,26 @@ func setupTimeouts() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ConfigLoad() {
|
func ConfigLoad() {
|
||||||
// configuration parsing
|
// use .env file if it exists
|
||||||
if err := ff.Parse(flagset, os.Args[1:],
|
if _, err := os.Stat(".env"); err == nil {
|
||||||
ff.WithEnvVarPrefix("smtprelay"),
|
if err := ff.Parse(flagset, os.Args[1:],
|
||||||
ff.WithConfigFileFlag("config"),
|
ff.WithEnvVarPrefix("smtprelay"),
|
||||||
ff.WithConfigFileParser(IniParser),
|
ff.WithConfigFile(".env"),
|
||||||
); err != nil {
|
ff.WithConfigFileParser(ff.EnvParser),
|
||||||
fmt.Fprintf(os.Stderr, "error: %v\n", err)
|
); err != nil {
|
||||||
os.Exit(1)
|
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"),
|
||||||
|
ff.WithConfigFileParser(IniParser),
|
||||||
|
); err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "error: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set up logging as soon as possible
|
// Set up logging as soon as possible
|
||||||
|
|||||||
Reference in New Issue
Block a user