Skip to content

BillionMail gives you open-source MailServer, NewsLetter, Email Marketing — fully self-hosted, dev-friendly, and free from monthly fees. Join the discord: https://discord.gg/asfXzBUhZr

feat: create empty sender relay maps and SASL password files if they do not exist

lotka82c162b6a4a
diff --git a/core/internal/service/relay/config_sync.go b/core/internal/service/relay/config_sync.go
index 1cc01b0d..bae51783 100644
--- a/core/internal/service/relay/config_sync.go
+++ b/core/internal/service/relay/config_sync.go
@@ -332,6 +332,41 @@ sender_dependent_default_transport_maps = pgsql:/etc/postfix/sql/pgsql_sender_tr
return
}
+func EnsurePostfixConfExists(ctx context.Context) {
+
+ senderRelayMapsPrimaryPath := path.Join(postfixConfigDir, senderRelayMapsPrimaryFile)
+ saslPasswdPrimaryPath := path.Join(postfixConfigDir, saslPasswdPrimaryFile)
+ needReload := false
+
+ if !gfile.Exists(senderRelayMapsPrimaryPath) {
+ needReload = true
+ if err := gfile.PutContents(senderRelayMapsPrimaryPath, "# Created on "+time.Now().Format("2006-01-02 15:04:05")+"\n# This file maps sender domains to relay hosts\n"); err != nil {
+ g.Log().Errorf(ctx, "Failed to create %s: %v", senderRelayMapsPrimaryPath, err)
+ } else {
+ g.Log().Info(ctx, "Created sender_relay_maps_primary file in SyncRelayConfigsToPostfix")
+ }
+ }
+
+ if !gfile.Exists(saslPasswdPrimaryPath) {
+ needReload = true
+ if err := gfile.PutContents(saslPasswdPrimaryPath, "# Created on "+time.Now().Format("2006-01-02 15:04:05")+"\n# This file contains SASL authentication credentials for relay hosts\n"); err != nil {
+ g.Log().Errorf(ctx, "Failed to create %s: %v", saslPasswdPrimaryPath, err)
+ } else {
+ g.Log().Info(ctx, "Created sasl_passwd_primary file in SyncRelayConfigsToPostfix")
+ }
+ }
+
+ if needReload {
+ if err := reloadPostfixConfigs2(ctx); err != nil {
+ g.Log().Errorf(ctx, "Failed to reload Postfix configs after creating necessary files: %v", err)
+
+ } else {
+ g.Log().Info(ctx, "Successfully initialized and reloaded Postfix configs")
+ }
+ }
+
+}
+
func reloadPostfixConfigs2(ctx context.Context) error {
dk, err := docker.NewDockerAPI()
diff --git a/core/internal/service/timers/timers.go b/core/internal/service/timers/timers.go
index 75e08ac1..d9730c09 100644
--- a/core/internal/service/timers/timers.go
+++ b/core/internal/service/timers/timers.go
@@ -179,6 +179,10 @@ func Start(ctx context.Context) (err error) {
}
})
+ gtimer.AddOnce(1*time.Minute, func() {
+ relay.EnsurePostfixConfExists(ctx)
+ })
+
g.Log().Debug(ctx, "All timers started successfully")
return nil
}