feat: patched frappe email to work with frappecloud mail app (#15248)
* feat: patched EmailQueue.send and frappe.utils.get_formatted_email * chore: renamed hooks and handled an edge case * fix: if the get_sender_details hook is defined but it returns invalid input
This commit is contained in:
parent
6fc0a7e5f4
commit
1ec54c87c8
2 changed files with 14 additions and 4 deletions
|
|
@ -18,7 +18,7 @@ from frappe import _, safe_encode, task
|
|||
from frappe.model.document import Document
|
||||
from frappe.email.queue import get_unsubcribed_url, get_unsubscribe_message
|
||||
from frappe.email.email_body import add_attachment, get_formatted_html, get_email
|
||||
from frappe.utils import cint, split_emails, add_days, nowdate, cstr
|
||||
from frappe.utils import cint, split_emails, add_days, nowdate, cstr, get_hook_method
|
||||
from frappe.email.doctype.email_account.email_account import EmailAccount
|
||||
|
||||
|
||||
|
|
@ -121,9 +121,13 @@ class EmailQueue(Document):
|
|||
continue
|
||||
|
||||
message = ctx.build_message(recipient.recipient)
|
||||
if not frappe.flags.in_test:
|
||||
ctx.smtp_session.sendmail(from_addr=self.sender, to_addrs=recipient.recipient, msg=message)
|
||||
ctx.add_to_sent_list(recipient)
|
||||
method = get_hook_method('override_email_send')
|
||||
if method:
|
||||
method(self, self.sender, recipient.recipient, message)
|
||||
else:
|
||||
if not frappe.flags.in_test:
|
||||
ctx.smtp_session.sendmail(from_addr=self.sender, to_addrs=recipient.recipient, msg=message)
|
||||
ctx.add_to_sent_list(recipient)
|
||||
|
||||
if frappe.flags.in_test:
|
||||
frappe.flags.sent_mail = message
|
||||
|
|
|
|||
|
|
@ -56,6 +56,12 @@ def get_email_address(user=None):
|
|||
def get_formatted_email(user, mail=None):
|
||||
"""get Email Address of user formatted as: `John Doe <johndoe@example.com>`"""
|
||||
fullname = get_fullname(user)
|
||||
|
||||
method = get_hook_method('get_sender_details')
|
||||
if method:
|
||||
sender_name, mail = method()
|
||||
# if method exists but sender_name is ""
|
||||
fullname = sender_name or fullname
|
||||
|
||||
if not mail:
|
||||
mail = get_email_address(user) or validate_email_address(user)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue