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
Periodically update the billionmail_hostname tag file billionmail_hostname.txt
lotk71deb373e16c
diff --git a/core/internal/service/settings/billionmail_hostname.go b/core/internal/service/settings/billionmail_hostname.gonew file mode 100644index 00000000..79281635--- /dev/null+++ b/core/internal/service/settings/billionmail_hostname.go@@ -0,0 +1,33 @@+package settings++import (+ "billionmail-core/internal/service/domains"+ "billionmail-core/internal/service/public"+ "os"+)++// 检查BILLIONMAIL_HOSTNAME的A记录是否与本机公网IP一致,写入或删除标记文件+func CheckHostname() {+ hostname := public.MustGetDockerEnv("BILLIONMAIL_HOSTNAME", "")+ flagFile := public.AbsPath("../core/data/billionmail_hostname.txt")++ if hostname == "" || hostname == "mail.example.com" {+ _ = os.Remove(flagFile)+ return+ }++ record, err := domains.GetARecord(hostname, true)+ if err != nil || !record.Valid {+ _ = os.Remove(flagFile)+ return+ }++ serverIP := record.Value+ if serverIP == "" {+ _ = os.Remove(flagFile)+ return+ }++ // 只要A记录有效且IP不为空就写入+ _ = os.WriteFile(flagFile, []byte(hostname), 0644)+}diff --git a/core/internal/service/timers/timers.go b/core/internal/service/timers/timers.goindex 03612978..12b8d264 100644--- a/core/internal/service/timers/timers.go+++ b/core/internal/service/timers/timers.go@@ -9,6 +9,7 @@ import ("billionmail-core/internal/service/mail_service""billionmail-core/internal/service/maillog_stat""billionmail-core/internal/service/relay"+ "billionmail-core/internal/service/settings""billionmail-core/internal/service/warmup""context""github.com/gogf/gf/os/gtimer"@@ -142,6 +143,13 @@ func Start(ctx context.Context) (err error) {// fail2ban access logs detectiongtimer.AddOnce(800*time.Millisecond, fail2ban.NewAccessLogDetection().Start)+ gtimer.AddOnce(500*time.Millisecond, func() {+ settings.CheckHostname()+ })+ gtimer.Add(24*time.Hour, func() {+ settings.CheckHostname()+ })+g.Log().Debug(ctx, "All timers started successfully")return nil}