Send unsubscribe message in email option added to Email Account (#2298)
This commit is contained in:
parent
7757aaef6a
commit
ca22d756e3
5 changed files with 46 additions and 8 deletions
|
|
@ -120,6 +120,11 @@ def _notify(doc, print_html=None, print_format=None, attachments=None,
|
|||
|
||||
prepare_to_notify(doc, print_html, print_format, attachments)
|
||||
|
||||
if doc.outgoing_email_account.send_unsubscribe_message:
|
||||
unsubscribe_message = _("Leave this conversation")
|
||||
else:
|
||||
unsubscribe_message = ""
|
||||
|
||||
frappe.sendmail(
|
||||
recipients=(recipients or []) + (cc or []),
|
||||
show_as_cc=(cc or []),
|
||||
|
|
@ -132,7 +137,7 @@ def _notify(doc, print_html=None, print_format=None, attachments=None,
|
|||
reference_name=doc.reference_name,
|
||||
attachments=doc.attachments,
|
||||
message_id=doc.name,
|
||||
unsubscribe_message=_("Leave this conversation"),
|
||||
unsubscribe_message=unsubscribe_message,
|
||||
delayed=True,
|
||||
communication=doc.name
|
||||
)
|
||||
|
|
@ -252,7 +257,7 @@ def set_incoming_outgoing_accounts(doc):
|
|||
if not doc.outgoing_email_account:
|
||||
doc.outgoing_email_account = frappe.db.get_value("Email Account",
|
||||
{"default_outgoing": 1, "enable_outgoing": 1},
|
||||
["email_id", "always_use_account_email_id_as_sender", "name"], as_dict=True) or frappe._dict()
|
||||
["email_id", "always_use_account_email_id_as_sender", "name", "send_unsubscribe_message"], as_dict=True) or frappe._dict()
|
||||
|
||||
def get_recipients(doc, fetched_from_email_account=False):
|
||||
"""Build a list of email addresses for To"""
|
||||
|
|
|
|||
|
|
@ -773,6 +773,35 @@
|
|||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"default": "1",
|
||||
"fieldname": "send_unsubscribe_message",
|
||||
"fieldtype": "Check",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Send unsubscribe message in email",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
|
|
@ -1013,7 +1042,7 @@
|
|||
"issingle": 0,
|
||||
"istable": 0,
|
||||
"max_attachments": 0,
|
||||
"modified": "2016-11-07 05:52:23.155592",
|
||||
"modified": "2016-11-10 09:03:32.378017",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Email",
|
||||
"name": "Email Account",
|
||||
|
|
|
|||
|
|
@ -360,6 +360,11 @@ class EmailAccount(Document):
|
|||
if self.enable_auto_reply:
|
||||
set_incoming_outgoing_accounts(communication)
|
||||
|
||||
if self.send_unsubscribe_message:
|
||||
unsubscribe_message = _("Leave this conversation")
|
||||
else:
|
||||
unsubscribe_message = ""
|
||||
|
||||
frappe.sendmail(recipients = [email.from_email],
|
||||
sender = self.email_id,
|
||||
reply_to = communication.incoming_email_account,
|
||||
|
|
@ -370,7 +375,7 @@ class EmailAccount(Document):
|
|||
reference_name = communication.reference_name,
|
||||
message_id = communication.name,
|
||||
in_reply_to = email.mail.get("Message-Id"), # send back the Message-Id as In-Reply-To
|
||||
unsubscribe_message = _("Leave this conversation"))
|
||||
unsubscribe_message = unsubscribe_message)
|
||||
|
||||
def get_unreplied_notification_emails(self):
|
||||
"""Return list of emails listed"""
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ def send(recipients=None, sender=None, subject=None, message=None, reference_doc
|
|||
email_content = formatted
|
||||
email_text_context = text_content
|
||||
|
||||
if reference_doctype:
|
||||
if reference_doctype and (unsubscribe_message or reference_doctype=="Newsletter"):
|
||||
unsubscribe_link = get_unsubscribe_link(
|
||||
reference_doctype=reference_doctype,
|
||||
reference_name=reference_name,
|
||||
|
|
@ -101,7 +101,6 @@ def send(recipients=None, sender=None, subject=None, message=None, reference_doc
|
|||
|
||||
email_content = email_content.replace("<!-- cc message -->", cc_message)
|
||||
email_text_context = cc_message + "\n" + email_text_context
|
||||
|
||||
# add to queue
|
||||
add(email, sender, subject, email_content, email_text_context, reference_doctype,
|
||||
reference_name, attachments, reply_to, cc, message_id, in_reply_to, send_after, send_priority, email_account=email_account, communication=communication)
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class TestEmail(unittest.TestCase):
|
|||
send(recipients = ['test@example.com', 'test1@example.com'],
|
||||
sender="admin@example.com",
|
||||
reference_doctype='User', reference_name='Administrator',
|
||||
subject='Testing Queue', message='This mail is queued!', send_after=send_after)
|
||||
subject='Testing Queue', message='This mail is queued!', unsubscribe_message="Unsubscribe", send_after=send_after)
|
||||
|
||||
email_queue = frappe.db.sql("""select * from `tabEmail Queue` where status='Not Sent'""", as_dict=1)
|
||||
self.assertEquals(len(email_queue), 2)
|
||||
|
|
@ -69,7 +69,7 @@ class TestEmail(unittest.TestCase):
|
|||
send(recipients = ['test@example.com', 'test1@example.com'],
|
||||
sender="admin@example.com",
|
||||
reference_doctype='User', reference_name= "Administrator",
|
||||
subject='Testing Email Queue', message='This is mail is queued!')
|
||||
subject='Testing Email Queue', message='This is mail is queued!', unsubscribe_message="Unsubscribe")
|
||||
|
||||
# this is sent async (?)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue