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

Update config.yaml, change SessionCookieMaxAge to 30days. Optimized domain module, added a hostname parameter to solve the hard-code issue. Fixed SMTP relay using port 465 cannot send email.

Jackd0f6e8cd364d
diff --git a/core/api/domains/v1/domains.go b/core/api/domains/v1/domains.go
index b0e72336..9967c3d2 100644
--- a/core/api/domains/v1/domains.go
+++ b/core/api/domains/v1/domains.go
@@ -55,6 +55,7 @@ type AddDomainReq struct {
g.Meta `path:"/domains/create" tags:"Domain" method:"post" sm:"Add domain" in:"body"`
Authorization string `json:"authorization" dc:"Authorization" in:"header"`
Domain string `json:"domain" v:"required|domain" dc:"Domain"`
+ Hostname string `json:"hostname" v:"domain" dc:"Hostname, used for A record"`
Mailboxes int `json:"mailboxes" v:"min:1" dc:"Mailboxes" d:"50"`
MailboxQuota int `json:"mailboxQuota" v:"min:1" dc:"MailboxQuota" d:"5242880"`
Quota int `json:"quota" v:"required" dc:"Quota" d:"10485760"`
@@ -72,6 +73,7 @@ type UpdateDomainReq struct {
g.Meta `path:"/domains/update" tags:"Domain" method:"post" sm:"Update domain" in:"body"`
Authorization string `json:"authorization" dc:"Authorization" in:"header"`
Domain string `json:"domain" v:"required|domain" dc:"Domain"`
+ Hostname string `json:"hostname" v:"domain" dc:"Hostname, used for A record"`
Mailboxes int `json:"mailboxes" v:"min:1" dc:"Mailboxes" d:"50"`
MailboxQuota int `json:"mailboxQuota" v:"min:1" dc:"MailboxQuota" d:"5242880"`
Quota int `json:"quota" dc:"Quota" d:"10485760"`
diff --git a/core/internal/controller/domains/domains_v1_add_domain.go b/core/internal/controller/domains/domains_v1_add_domain.go
index 1a6a750a..8c1968b8 100644
--- a/core/internal/controller/domains/domains_v1_add_domain.go
+++ b/core/internal/controller/domains/domains_v1_add_domain.go
@@ -16,9 +16,13 @@ import (
func (c *ControllerV1) AddDomain(ctx context.Context, req *v1.AddDomainReq) (res *v1.AddDomainRes, err error) {
res = &v1.AddDomainRes{}
+ if req.Hostname == "" {
+ req.Hostname = public.FormatMX(req.Domain)
+ }
+
domain := &v1.Domain{
Domain: req.Domain,
- ARecord: "mail." + req.Domain,
+ ARecord: req.Hostname,
Mailboxes: req.Mailboxes,
MailboxQuota: int64(req.MailboxQuota),
Quota: int64(req.Quota),
diff --git a/core/internal/controller/domains/domains_v1_update_domain.go b/core/internal/controller/domains/domains_v1_update_domain.go
index 302ae89b..f1b0eb0b 100644
--- a/core/internal/controller/domains/domains_v1_update_domain.go
+++ b/core/internal/controller/domains/domains_v1_update_domain.go
@@ -23,6 +23,10 @@ func (c *ControllerV1) UpdateDomain(ctx context.Context, req *v1.UpdateDomainReq
domainName := req.Domain
updateData["domain"] = domainName
+ if req.Hostname != "" {
+ updateData["a_record"] = req.Hostname
+ }
+
if req.Catchall != "" {
updateData["catchall"] = req.Catchall
}
diff --git a/core/internal/controller/relay/relay_v1_create_relay_config.go b/core/internal/controller/relay/relay_v1_create_relay_config.go
index 5ba8ab16..dae8542b 100644
--- a/core/internal/controller/relay/relay_v1_create_relay_config.go
+++ b/core/internal/controller/relay/relay_v1_create_relay_config.go
@@ -74,7 +74,7 @@ func (c *ControllerV1) CreateRelayConfig(ctx context.Context, req *v1.CreateRela
}
// HELO hostname: Default is mail.SenderDomain
if req.HeloName == "" {
- data["helo_name"] = "mail." + req.SenderDomain
+ data["helo_name"] = public.FormatMX(req.SenderDomain)
} else {
data["helo_name"] = req.HeloName
}
diff --git a/core/internal/service/domains/domains.go b/core/internal/service/domains/domains.go
index a953351a..f15b521d 100644
--- a/core/internal/service/domains/domains.go
+++ b/core/internal/service/domains/domains.go
@@ -614,7 +614,7 @@ func GetMXRecord(domain string, validateImmediate bool) (record v1.DNSRecord, er
record = v1.DNSRecord{
Type: "MX",
Host: "@",
- Value: "mail." + domain,
+ Value: public.FormatMX(domain),
}
if validateImmediate {
@@ -642,7 +642,7 @@ func GetARecord(domain string, validateImmediate bool) (record v1.DNSRecord, err
record = v1.DNSRecord{
Type: recordType,
- Host: "mail." + domain,
+ Host: public.FormatMX(domain),
Value: serverIP,
}
@@ -666,7 +666,7 @@ func GetPTRRecord(domain string, validateImmediate bool) (record v1.DNSRecord, e
record = v1.DNSRecord{
Type: "PTR",
Host: serverIP,
- Value: "mail." + domain,
+ Value: public.FormatMX(domain),
}
if validateImmediate {
diff --git a/core/internal/service/mail_service/certificate.go b/core/internal/service/mail_service/certificate.go
index ff38846c..db4f8655 100644
--- a/core/internal/service/mail_service/certificate.go
+++ b/core/internal/service/mail_service/certificate.go
@@ -299,7 +299,7 @@ func (c *Certificate) updatePostfixVMailConfig(domain, csrPem, keyPem string) er
}
// Create SNI mapping table
- if err := c.updatePostfixSNIMap("mail."+strings.TrimPrefix(domain, "mail."), vmailCert, vmailKey); err != nil {
+ if err := c.updatePostfixSNIMap(public.FormatMX(domain), vmailCert, vmailKey); err != nil {
return fmt.Errorf("failed to update SNI map: %v", err)
}
diff --git a/core/internal/service/mail_service/sending.go b/core/internal/service/mail_service/sending.go
index 27a1afec..cee05060 100644
--- a/core/internal/service/mail_service/sending.go
+++ b/core/internal/service/mail_service/sending.go
@@ -389,11 +389,13 @@ func (e *EmailSender) doSend(message Message, recipients []string) error {
}()
// Set the sender
+ // MAIL FROM
if err = e.client.Mail(e.Email); err != nil {
return fmt.Errorf("SMTP mail: %w", err)
}
// Set the recipients
+ // RCPT TO
for _, to := range recipients {
if err = e.client.Rcpt(to); err != nil {
return fmt.Errorf("SMTP rcpt: %w", err)
diff --git a/core/internal/service/public/common.go b/core/internal/service/public/common.go
index 717d2d2a..63884281 100644
--- a/core/internal/service/public/common.go
+++ b/core/internal/service/public/common.go
@@ -2656,6 +2656,12 @@ func AddUnsubscribeButton(content string) string {
// FormatMX format the email domain
func FormatMX(domain string) string {
+ val, err := g.DB().Model("domain").Where("domain", domain).Value("a_record")
+
+ if err == nil && !val.IsEmpty() {
+ return val.String()
+ }
+
return "mail." + strings.TrimPrefix(domain, "mail.")
}
diff --git a/core/internal/service/relay/config_sync.go b/core/internal/service/relay/config_sync.go
index ec5288e2..36c41be5 100644
--- a/core/internal/service/relay/config_sync.go
+++ b/core/internal/service/relay/config_sync.go
@@ -290,8 +290,11 @@ func generateRelayConfigFiles(ctx context.Context, configs []*entity.BmRelay) er
smtpName = fmt.Sprintf("smtp_%s", cleanedSmtpName)
}
- senderTransportContent.WriteString(fmt.Sprintf("%s %s:[%s]:%s\n",
- strings.TrimPrefix(senderDomain, "@"), smtpName, config.RelayHost, config.RelayPort))
+ //senderTransportContent.WriteString(fmt.Sprintf("%s %s:[%s]:%s\n",
+ // strings.TrimPrefix(senderDomain, "@"), smtpName, config.RelayHost, config.RelayPort))
+
+ senderTransportContent.WriteString(fmt.Sprintf("%s %s:\n",
+ senderDomain, smtpName))
}
}
@@ -322,6 +325,12 @@ func updatePostfixMasterCf(ctx context.Context, configs []*entity.BmRelay) error
// Read existing content
masterContent := gfile.GetContents(masterCfPath)
+ // Define the smtps configuration to add
+ masterContent, smtpsChanged := ensureSmtpsConfigInMasterCf(masterContent)
+ if smtpsChanged {
+ g.Log().Info(ctx, "smtps configuration block updated in master.cf")
+ }
+
beginMarker := "# BEGIN BILLIONMAIL RELAY CONFIG - DO NOT EDIT THIS MARKER"
endMarker := "# END BILLIONMAIL RELAY CONFIG - DO NOT EDIT THIS MARKER"
@@ -590,3 +599,52 @@ smtp_sasl_mechanism_filter = login, plain, cram-md5
return nil
}
+
+func ensureSmtpsConfigInMasterCf(content string) (string, bool) {
+ const (
+ markerBegin = "# BEGIN BILLIONMAIL SMTPS CONFIG - DO NOT EDIT THIS MARKER"
+ markerEnd = "# END BILLIONMAIL SMTPS CONFIG - DO NOT EDIT THIS MARKER"
+ )
+ smtpsService := `smtps unix - - n - - smtp
+ -o smtp_tls_wrappermode=yes
+ -o smtp_tls_security_level=encrypt`
+
+ var block strings.Builder
+ block.WriteString(markerBegin + "\n")
+ block.WriteString(smtpsService + "\n")
+ block.WriteString(markerEnd + "\n")
+ smtpsBlock := block.String()
+
+ beginIndex := strings.Index(content, markerBegin)
+ endIndex := strings.Index(content, markerEnd)
+ hasBlock := beginIndex != -1 && endIndex != -1 && beginIndex < endIndex
+
+ if hasBlock {
+ blockEnd := endIndex + len(markerEnd)
+
+ for blockEnd < len(content) && (content[blockEnd] == '\n' || content[blockEnd] == '\r') {
+ blockEnd++
+ }
+
+ existingBlock := content[beginIndex:blockEnd]
+ if strings.Contains(existingBlock, smtpsService) {
+
+ return content, false
+ }
+
+ newContent := content[:beginIndex] + smtpsBlock
+ if blockEnd < len(content) {
+ newContent += content[blockEnd:]
+ }
+ return newContent, true
+ }
+
+ var updated string
+ if !strings.HasSuffix(content, "\n") {
+ updated = content + "\n"
+ } else {
+ updated = content
+ }
+ updated += "\n" + smtpsBlock
+ return updated, true
+}
diff --git a/core/manifest/config/config.yaml b/core/manifest/config/config.yaml
index 89da055f..3f7d7777 100644
--- a/core/manifest/config/config.yaml
+++ b/core/manifest/config/config.yaml
@@ -20,9 +20,14 @@ server:
cookieMaxAge: "365d"
cookiePath: "/"
cookieDomain: ""
+ cookieSameSite: "Lax" # Options: Lax, Strict, None
+ cookieSecure: true # Whether to use secure cookies, only effective when HTTPS is enabled
+ cookieHttpOnly: true # Whether to enable HttpOnly, preventing JavaScript from accessing cookies
+
# Sessions Configuration
sessionMaxAge: "30d"
+ sessionCookieMaxAge: "30d" # Session cookie maximum age, default is 30 days
sessionIdName: "billion_mail"
sessionCookieOutput: true
sessionPath: "data/session"