Skip to content

Commit

Permalink
fix Domain var
Browse files Browse the repository at this point in the history
  • Loading branch information
yumusb committed Sep 24, 2024
1 parent 6b95017 commit 554908d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 2 additions & 0 deletions deploy/compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ services:
- ./config.yml:/app/config.yml:ro
- ./cert:/cert/
restart: always
environment:
- MXDOMAIN=${MXDOMAIN}
ports:
- "25:25"
- "587:587"
Expand Down
15 changes: 10 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,14 @@ func LoadConfig(filePath string) error {
}
return nil
}

func GetEnv(key, defaultValue string) string {
if value, exists := os.LookupEnv(key); exists {
return value
}
return defaultValue
}
func main() {

log.SetFlags(log.LstdFlags | log.Lshortfile)
err := LoadConfig("config.yml")
if err != nil {
log.Fatalf("Error loading config: %v", err)
Expand All @@ -70,7 +75,7 @@ func main() {
// Plain SMTP server with STARTTLS support
plainServer := smtp.NewServer(be)
plainServer.Addr = CONFIG.SMTP.ListenAddress
plainServer.Domain = "localhost"
plainServer.Domain = GetEnv("MXDOMAIN", "localhost")
plainServer.WriteTimeout = 10 * time.Second
plainServer.ReadTimeout = 10 * time.Second
plainServer.MaxMessageBytes = 1024 * 1024
Expand All @@ -94,7 +99,7 @@ func main() {
// SMTPS server (TLS only)
tlsServer := smtp.NewServer(be)
tlsServer.Addr = CONFIG.SMTP.ListenAddressTls
tlsServer.Domain = "localhost"
tlsServer.Domain = GetEnv("MXDOMAIN", "localhost")
tlsServer.WriteTimeout = 10 * time.Second
tlsServer.ReadTimeout = 10 * time.Second
tlsServer.MaxMessageBytes = 1024 * 1024
Expand Down Expand Up @@ -271,7 +276,7 @@ func getSMTPServer(domain string) (string, error) {
return mxRecords[0].Host, nil
}
func forwardEmailToTargetAddress(emailData []byte, formattedSender string, targetAddress string) {
log.Printf("Preparing to forward email from %s to %s", formattedSender, targetAddress)
log.Printf("Preparing to forward email from [%s] to [%s]", formattedSender, targetAddress)
if formattedSender == "" || targetAddress == "" {
log.Println("address error")
return
Expand Down

0 comments on commit 554908d

Please sign in to comment.