feat: Inject footer and header within an HTML Email Template

This commit is contained in:
Alex Leach 2025-11-19 08:09:36 +00:00
parent b82b336891
commit 75b481a4f9
No known key found for this signature in database
GPG key ID: CBB1F1542760286C
2 changed files with 23 additions and 3 deletions

View file

@ -37,19 +37,38 @@ class EmailTemplate(Document):
def get_formatted_response(self, doc):
return frappe.render_template(self.response_, doc)
def get_formatted_email(self, doc):
def get_formatted_email(self, doc, sender=None):
if isinstance(doc, str):
doc = json.loads(doc)
if self.use_html:
doc = self.inject_email_account(doc, sender)
return {
"subject": self.get_formatted_subject(doc),
"message": self.get_formatted_response(doc),
}
def inject_email_account(self, doc, sender=None):
from frappe.email.doctype.email_account.email_account import EmailAccount
from frappe.email.email_body import get_footer, get_signature
if sender:
kwargs = {"match_by_email": sender}
else:
kwargs = {"match_by_doctype": doc.get("doctype")}
email_account = EmailAccount.find_outgoing(**kwargs)
if email_account:
doc.update(
{"email_signature": get_signature(email_account), "email_footer": get_footer(email_account)}
)
return doc
@frappe.whitelist()
def get_email_template(template_name, doc):
def get_email_template(template_name, doc, sender=None):
"""Return the processed HTML of a email template with the given doc"""
email_template = frappe.get_doc("Email Template", template_name)
return email_template.get_formatted_email(doc)
return email_template.get_formatted_email(doc, sender=sender)

View file

@ -450,6 +450,7 @@ frappe.views.CommunicationComposer = class {
args: {
template_name: email_template,
doc: me.doc,
sender: me.dialog.get_value("sender") || "",
},
callback(r) {
prepend_reply(r.message);