8000 fix: outgoing email account handlng by ankush · Pull Request #24656 · frappe/frappe · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: outgoing email account handlng #24656

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions frappe/email/doctype/email_queue/email_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ def to(self):
def attachments_list(self):
return json.loads(self.attachments) if self.attachments else []

def get_email_account(self):
def get_email_account(self, raise_error=False):
if self.email_account:
return frappe.get_cached_doc("Email Account", self.email_account)

return EmailAccount.find_outgoing(
match_by_email=self.sender, match_by_doctype=self.reference_doctype
match_by_email=self.sender, match_by_doctype=self.reference_doctype, _raise_error=raise_error
)

def is_to_be_sent(self):
Expand All @@ -158,6 +158,7 @@ def send(self, smtp_server_instance: SMTPServer = None):
return

with SendMailContext(self, smtp_server_instance) as ctx:
ctx.fetch_smtp_server()
message = None
for recipient in self.recipients:
if recipient.is_mail_sent():
Expand Down Expand Up @@ -233,14 +234,16 @@ def __init__(
smtp_server_instance: SMTPServer = None,
):
self.queue_doc: EmailQueue = queue_doc
self.email_account_doc = queue_doc.get_email_account()

self.smtp_server: SMTPServer = smtp_server_instance or self.email_account_doc.get_smtp_server()

self.smtp_server: SMTPServer = smtp_server_instance
self.sent_to_atleast_one_recipient = any(
rec.recipient for rec in self.queue_doc.recipients if rec.is_mail_sent()
)

def fetch_smtp_server(self):
self.email_account_doc = self.queue_doc.get_email_account(raise_error=True)
if not self.smtp_server:
self.smtp_server = self.email_account_doc.get_smtp_server()

def __enter__(self):
self.queue_doc.update_status(status="Sending", commit=True)
return self
Expand Down Expand Up @@ -733,7 +736,7 @@ def send_emails(self, queue_data, final_recipients):
recipients = list(set([r] + self.final_cc() + self.bcc))
q = EmailQueue.new({**queue_data, **{"recipients": recipients}}, ignore_permissions=True)
if not smtp_server_instance:
email_account = q.get_email_account()
email_account = q.get_email_account(raise_error=True)
smtp_server_instance = email_account.get_smtp_server()

with suppress(Exception):
Expand Down
0