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:
Rutwik Hiwalkar 2021-12-12 21:09:31 +05:30 committed by GitHub
parent 6fc0a7e5f4
commit 1ec54c87c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 4 deletions

View file

@ -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

View file

@ -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)