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

Periodically update the billionmail_hostname tag file billionmail_hostname.txt

lotkcdad6b4070b1
diff --git a/core/internal/service/settings/billionmail_hostname.go b/core/internal/service/settings/billionmail_hostname.go
index 79281635..bc2c470f 100644
--- a/core/internal/service/settings/billionmail_hostname.go
+++ b/core/internal/service/settings/billionmail_hostname.go
@@ -1,12 +1,14 @@
package settings
import (
+ v1 "billionmail-core/api/domains/v1"
"billionmail-core/internal/service/domains"
"billionmail-core/internal/service/public"
"os"
+ "strings"
)
-// 检查BILLIONMAIL_HOSTNAME的A记录是否与本机公网IP一致,写入或删除标记文件
+// Check whether the A record of BILLIONMAIL_HOSTNAME is consistent with the local public network IP and write or delete the tag file
func CheckHostname() {
hostname := public.MustGetDockerEnv("BILLIONMAIL_HOSTNAME", "")
flagFile := public.AbsPath("../core/data/billionmail_hostname.txt")
@@ -16,18 +18,26 @@ func CheckHostname() {
return
}
- record, err := domains.GetARecord(hostname, true)
- if err != nil || !record.Valid {
- _ = os.Remove(flagFile)
+ serverIP, err := public.GetServerIP()
+
+ if err != nil {
return
}
- serverIP := record.Value
- if serverIP == "" {
- _ = os.Remove(flagFile)
- return
+ recordType := "A"
+ if strings.Contains(serverIP, ":") {
+ recordType = "AAAA"
+ }
+
+ record := v1.DNSRecord{
+ Type: recordType,
+ Host: hostname,
+ Value: serverIP,
+ }
+
+ Valid := domains.ValidateARecord(record)
+ if Valid {
+ _ = os.WriteFile(flagFile, []byte(hostname), 0644)
}
- // 只要A记录有效且IP不为空就写入
- _ = os.WriteFile(flagFile, []byte(hostname), 0644)
}