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

Fix the UnsubscribeURL

lotk31f12110704d
diff --git a/core/internal/controller/batch_mail/batch_mail_v1_send_test_email.go b/core/internal/controller/batch_mail/batch_mail_v1_send_test_email.go
index 923bff41..0a9ef93f 100644
--- a/core/internal/controller/batch_mail/batch_mail_v1_send_test_email.go
+++ b/core/internal/controller/batch_mail/batch_mail_v1_send_test_email.go
@@ -39,11 +39,11 @@ func (c *ControllerV1) SendTestEmail(ctx context.Context, req *v1.SendTestEmailR
return
}
- if !strings.Contains(template.Content, "{{ UnsubscribeURL }}") {
+ if !strings.Contains(template.Content, "{{ UnsubscribeURL . }}") {
template.Content = public.AddUnsubscribeButton(template.Content)
}
- content := strings.ReplaceAll(template.Content, "__UNSUBSCRIBE_URL__", "{{ UnsubscribeURL }}")
+ content := strings.ReplaceAll(template.Content, "__UNSUBSCRIBE_URL__", "{{ UnsubscribeURL . }}")
jwtToken, _ := batch_mail.GenerateUnsubscribeJWT(req.Recipient, req.TemplateId, 0)
domain := domains.GetBaseURL()
diff --git a/core/internal/service/batch_mail/task_executor.go b/core/internal/service/batch_mail/task_executor.go
index 1bb456c7..32bfe56c 100644
--- a/core/internal/service/batch_mail/task_executor.go
+++ b/core/internal/service/batch_mail/task_executor.go
@@ -861,11 +861,11 @@ func (e *TaskExecutor) processEmailContent(ctx context.Context, content string,
// process unsubscribe link
if task.Unsubscribe == 1 {
// __UNSUBSCRIBE_URL__ {{ UnsubscribeURL }}
- if !strings.Contains(content, "__UNSUBSCRIBE_URL__") && !strings.Contains(content, "{{ UnsubscribeURL }}") {
+ if !strings.Contains(content, "__UNSUBSCRIBE_URL__") && !strings.Contains(content, "{{ UnsubscribeURL . }}") {
content = public.AddUnsubscribeButton(content)
}
- content = strings.ReplaceAll(content, "__UNSUBSCRIBE_URL__", "{{ UnsubscribeURL }}")
+ content = strings.ReplaceAll(content, "__UNSUBSCRIBE_URL__", "{{ UnsubscribeURL . }}")
}
return content
}
diff --git a/core/internal/service/batch_mail/template_render.go b/core/internal/service/batch_mail/template_render.go
index dd202982..94ce4ccc 100644
--- a/core/internal/service/batch_mail/template_render.go
+++ b/core/internal/service/batch_mail/template_render.go
@@ -30,6 +30,16 @@ func NewTemplateEngine() *TemplateEngine {
}
return ""
},
+ "UnsubscribeURL": func(data ...interface{}) interface{} {
+ if len(data) > 0 {
+ if m, ok := data[0].(g.Map); ok {
+ if url, ok := m["UnsubscribeURL"].(string); ok {
+ return url
+ }
+ }
+ }
+ return ""
+ },
})
return &TemplateEngine{view: view}
diff --git a/core/internal/service/public/common.go b/core/internal/service/public/common.go
index 77bbcf24..2cb7ebc3 100644
--- a/core/internal/service/public/common.go
+++ b/core/internal/service/public/common.go
@@ -2547,10 +2547,10 @@ func SanitizeUTF8(s string) string {
func AddUnsubscribeButton(content string) string {
// Unsubscribe button HTML
- unsubscribeButton := `<div style="padding: 16px 0; text-align: center"><a href="{{ UnsubscribeURL }}" style="color: #ccc; font-size: 12px">Unsubscribe</a></div>`
+ unsubscribeButton := `<div style="padding: 16px 0; text-align: center"><a href="{{ UnsubscribeURL . }}" style="color: #ccc; font-size: 12px">Unsubscribe</a></div>`
// If content already contains unsubscribe link, return directly
- if strings.Contains(content, "{{ UnsubscribeURL }}") {
+ if strings.Contains(content, "{{ UnsubscribeURL . }}") {
return content
}