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
Email content: Restore the erroneous variable {{}}
lotk1e567bbd4b86
diff --git a/core/internal/service/batch_mail/task_executor.go b/core/internal/service/batch_mail/task_executor.goindex bcf9a89f..02694fe0 100644--- a/core/internal/service/batch_mail/task_executor.go+++ b/core/internal/service/batch_mail/task_executor.go@@ -15,6 +15,7 @@ import ("github.com/gogf/gf/v2/frame/g""github.com/gogf/gf/v2/os/gctx""github.com/panjf2000/ants/v2"+ "regexp""strings""sync""sync/atomic"@@ -993,9 +994,19 @@ func (e *TaskExecutor) personalizeEmail(ctx context.Context, content string, tas}}+ // Restore the erroneous variable+ renderedContent = e.restoreErrorVariables(renderedContent)+ renderedSubject = e.restoreErrorVariables(renderedSubject)+return renderedContent, renderedSubject}+// restoreErrorVariables 恢复 [__变量__] 为 {{变量}}+func (e *TaskExecutor) restoreErrorVariables(content string) string {+ re := regexp.MustCompile(`\[__([^_]+)__\]`)+ return re.ReplaceAllString(content, "{{$1}}")+}+// sendEmail send emailfunc (e *TaskExecutor) sendEmail(ctx context.Context, task *entity.EmailTask, recipient *entity.RecipientInfo, content string) *SendResult {// check if context is canceleddiff --git a/core/internal/service/batch_mail/template_render.go b/core/internal/service/batch_mail/template_render.goindex be407293..94234ba9 100644--- a/core/internal/service/batch_mail/template_render.go+++ b/core/internal/service/batch_mail/template_render.go@@ -188,7 +188,6 @@ func (e *TemplateEngine) cleanUndefinedVariables(content string) string {allVarRegex := regexp.MustCompile(`\{\{.*?\}\}`)content = allVarRegex.ReplaceAllStringFunc(content, func(match string) string {-inner := strings.TrimSpace(match[2 : len(match)-2])for _, pattern := range knownVariablePatterns {@@ -198,15 +197,14 @@ func (e *TemplateEngine) cleanUndefinedVariables(content string) string {}for _, fn := range knownFunctions {-fnRegex := regexp.MustCompile(`\s*` + regexp.QuoteMeta(fn) + `\s+[^}]*`)if fnRegex.MatchString(inner) {return match}}- // If no match is found with any of the known items, return the original variable name (without the {{}}).- return inner+ // If no match is found with any of the known items, replace with [__ __] format+ return "[__" + inner + "__]"})lines := strings.Split(content, "\n")