From 75b481a4f9e174db15f234c8ee57f9bf39f04e2b Mon Sep 17 00:00:00 2001 From: Alex Leach Date: Wed, 19 Nov 2025 08:09:36 +0000 Subject: [PATCH] feat: Inject footer and header within an HTML Email Template --- .../doctype/email_template/email_template.py | 25 ++++++++++++++++--- .../public/js/frappe/views/communication.js | 1 + 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/frappe/email/doctype/email_template/email_template.py b/frappe/email/doctype/email_template/email_template.py index b37598e051..b06e5c3977 100644 --- a/frappe/email/doctype/email_template/email_template.py +++ b/frappe/email/doctype/email_template/email_template.py @@ -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) diff --git a/frappe/public/js/frappe/views/communication.js b/frappe/public/js/frappe/views/communication.js index 286bf6ac52..0d3c7fe1be 100755 --- a/frappe/public/js/frappe/views/communication.js +++ b/frappe/public/js/frappe/views/communication.js @@ -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);