# render actual message content per sample engine = VariableEngine(c.variable_config or {}) out = [] for item in plan: rec = next((r for r in recipient_rows if r.id == item["recipient_id"]), None) if not rec: continue tpl = await db.get(EmailTemplate, item["template_id"]) if item.get("template_id") else None subj = await db.get(SubjectLine, item["subject_id"]) if item.get("subject_id") else None g = GeneratedValues() g.invoice_number = item.get("invoice_number", "") g.amount = item.get("amount") g.shipping = item.get("shipping") g.invoice_date = item.get("invoice_date") g.due_date = item.get("due_date") phone = item.get("phone", "") unsub = f"{cfg.UNSUBSCRIBE_BASE or cfg.BASE_URL}/unsubscribe/{rec.unsub_token}" if c.unsubscribe_enabled else "" extra = {"unsubscribe_link": unsub, "company_phone": phone} body_html = "" subject = "" warn_list = list(item.get("warnings") or []) if isinstance(item.get("warnings"), list) else ([item["warnings"]] if item.get("warnings") else []) if tpl: res = engine.substitute(tpl.body_html, rec, g, custom_fields=rec.custom_fields or {}, extra=extra) body_html = res.text subject = subj.subject if subj else (tpl.subject_hint or tpl.name) for u in res.unknown: warn_list.append(f"Unknown variable in body: {u}") for m_ in res.missing: warn_list.append(f"Missing data for: {m_}") if subj: res_s = engine.substitute(subj.subject, rec, g, custom_fields=rec.custom_fields or {}, extra=extra) subject = res_s.text for u in res_s.unknown: warn_list.append(f"Unknown variable in subject: {u}") for m_ in res_s.missing: warn_list.append(f"Missing data in subject: {m_}") out.append({ "recipient": {"id": rec.id, "email": rec.email, "first_name": rec.first_name, "last_name": rec.last_name}, "from_account": item.get("account", ""), "subject": subject, "body_html": sanitize_preview(body_html), ===== send engine subject ===== app/tasks/send_tasks.py:144: subject_row = db.get(SubjectLine, cr.generated_subject_id) if cr.generated_subject_id else None app/tasks/send_tasks.py:146: subject = subject_row.subject if subject_row else campaign.name app/tasks/send_tasks.py:214: subject=subject, app/tasks/send_tasks.py:219: unsubscribe_mailto=f"{account.email}?subject=unsubscribe", app/tasks/send_tasks.py:242: subject=subject,