diff --git a/frappe/core/doctype/communication/mixins.py b/frappe/core/doctype/communication/mixins.py index 655dbfe23f..833e4dcfac 100644 --- a/frappe/core/doctype/communication/mixins.py +++ b/frappe/core/doctype/communication/mixins.py @@ -278,13 +278,22 @@ class CommunicationEmailMixin: print_format=print_format, print_html=print_html, print_language=print_language ) incoming_email_account = self.get_incoming_email_account() + + reply_to = None + + # If this is a reply to an existing email, set reply_to as the sender of the reply + if self.in_reply_to: + reply_to = self.get_mail_sender_with_displayname() + elif incoming_email_account: + reply_to = incoming_email_account.email_id + return { "recipients": recipients, "cc": cc, "bcc": bcc, "expose_recipients": "header", "sender": self.get_mail_sender_with_displayname(), - "reply_to": incoming_email_account and incoming_email_account.email_id, + "reply_to": reply_to, "subject": self.subject, "content": self.get_content(print_format=print_format), "reference_doctype": self.reference_doctype, diff --git a/frappe/email/receive.py b/frappe/email/receive.py index abb26a3674..a6c6c00d61 100644 --- a/frappe/email/receive.py +++ b/frappe/email/receive.py @@ -9,7 +9,6 @@ import json import poplib import re import ssl -import time from contextlib import suppress from email.header import decode_header @@ -152,7 +151,7 @@ class EmailServer: def select_imap_folder(self, folder): res = self.imap.select(f'"{folder}"') - return res[0] == "OK" # The folder exsits TODO: handle other resoponses too + return res[0] == "OK" # The folder exists TODO: handle other responses too def logout(self): if cint(self.settings.use_imap): @@ -312,7 +311,6 @@ class EmailServer: return False def make_error_msg(self, uid, msg_num): - partial_mail = None traceback = frappe.get_traceback(with_context=True) with suppress(Exception): # retrieve headers