From 01aa5ff928e0324646a545d900f793180ffc1ff8 Mon Sep 17 00:00:00 2001 From: pateljannat Date: Fri, 22 Jan 2021 18:04:02 +0530 Subject: [PATCH 1/5] feat: newsletter modifications --- .../email/doctype/newsletter/newsletter.json | 27 ++++++++++++++++++- frappe/email/doctype/newsletter/newsletter.py | 3 ++- frappe/email/email_body.py | 14 +++++++--- frappe/email/queue.py | 12 +++++++-- frappe/templates/emails/email_footer.html | 8 ++++++ frappe/templates/emails/standard.html | 2 +- 6 files changed, 57 insertions(+), 9 deletions(-) diff --git a/frappe/email/doctype/newsletter/newsletter.json b/frappe/email/doctype/newsletter/newsletter.json index 1dd6115b43..c0383a7d75 100644 --- a/frappe/email/doctype/newsletter/newsletter.json +++ b/frappe/email/doctype/newsletter/newsletter.json @@ -19,9 +19,13 @@ "message", "message_md", "message_html", + "section_break_13", "send_unsubscribe_link", "send_attachments", + "full_width", + "column_break_9", "published", + "send_webview_link", "route", "test_the_newsletter", "test_email_id", @@ -160,6 +164,27 @@ "fieldtype": "Check", "label": "Schedule Sending", "read_only_depends_on": "eval: doc.email_sent" + }, + { + "fieldname": "column_break_9", + "fieldtype": "Column Break" + }, + { + "default": "0", + "depends_on": "published", + "fieldname": "send_webview_link", + "fieldtype": "Check", + "label": "Send Web View Link" + }, + { + "default": "0", + "fieldname": "full_width", + "fieldtype": "Check", + "label": "Full Width" + }, + { + "fieldname": "section_break_13", + "fieldtype": "Section Break" } ], "has_web_view": 1, @@ -169,7 +194,7 @@ "is_published_field": "published", "links": [], "max_attachments": 3, - "modified": "2020-08-24 19:59:37.262500", + "modified": "2021-01-20 20:21:53.535828", "modified_by": "Administrator", "module": "Email", "name": "Newsletter", diff --git a/frappe/email/doctype/newsletter/newsletter.py b/frappe/email/doctype/newsletter/newsletter.py index 2791ebb75b..eee71d038c 100755 --- a/frappe/email/doctype/newsletter/newsletter.py +++ b/frappe/email/doctype/newsletter/newsletter.py @@ -74,7 +74,8 @@ class Newsletter(WebsiteGenerator): add_unsubscribe_link=self.send_unsubscribe_link, attachments=attachments, unsubscribe_method="/unsubscribe", unsubscribe_params={"name": self.name}, - send_priority=0, queue_separately=True) + send_priority=0, queue_separately=True, add_web_link=self.send_webview_link, + is_newsletter=True, full_width=self.full_width) if not frappe.flags.in_test: frappe.db.auto_commit_on_many_writes = False diff --git a/frappe/email/email_body.py b/frappe/email/email_body.py index 8ac071fa61..49b6133c91 100755 --- a/frappe/email/email_body.py +++ b/frappe/email/email_body.py @@ -249,7 +249,8 @@ class EMail: return self.msg_root.as_string(policy=policy.SMTPUTF8) def get_formatted_html(subject, message, footer=None, print_html=None, - email_account=None, header=None, unsubscribe_link=None, sender=None): + email_account=None, header=None, unsubscribe_link=None, sender=None, + web_link=None, is_newsletter=False, full_width=False): if not email_account: email_account = get_outgoing_email_account(False, sender=sender) @@ -257,10 +258,12 @@ def get_formatted_html(subject, message, footer=None, print_html=None, "header": get_header(header), "content": message, "signature": get_signature(email_account), - "footer": get_footer(email_account, footer), + "footer": get_footer(email_account, footer, web_link), "title": subject, "print_html": print_html, - "subject": subject + "subject": subject, + "is_newsletter": is_newsletter, + "full_width": full_width }) html = scrub_urls(rendered_email) @@ -357,7 +360,7 @@ def get_signature(email_account): else: return "" -def get_footer(email_account, footer=None): +def get_footer(email_account, footer=None, web_link=None): """append a footer (signature)""" footer = footer or "" @@ -370,6 +373,9 @@ def get_footer(email_account, footer=None): if company_address: args.update({'company_address': company_address}) + + if web_link: + args.update({'web_link': web_link}) if not cint(frappe.db.get_default("disable_standard_email_footer")): args.update({'default_mail_footer': frappe.get_hooks('default_mail_footer')}) diff --git a/frappe/email/queue.py b/frappe/email/queue.py index f780aebdc1..71a9054e0b 100755 --- a/frappe/email/queue.py +++ b/frappe/email/queue.py @@ -24,7 +24,7 @@ def send(recipients=None, sender=None, subject=None, message=None, text_content= attachments=None, reply_to=None, cc=None, bcc=None, message_id=None, in_reply_to=None, send_after=None, expose_recipients=None, send_priority=1, communication=None, now=False, read_receipt=None, queue_separately=False, is_notification=False, add_unsubscribe_link=1, inline_images=None, - header=None, print_letterhead=False): + header=None, print_letterhead=False, is_newsletter=False, full_width=False, add_web_link=False): """Add email to sending queue (Email Queue) :param recipients: List of recipients. @@ -48,6 +48,9 @@ def send(recipients=None, sender=None, subject=None, message=None, text_content= :param add_unsubscribe_link: Send unsubscribe link in the footer of the Email, default 1. :param inline_images: List of inline images as {"filename", "filecontent"}. All src properties will be replaced with random Content-Id :param header: Append header in email (boolean) + :param is_newsletter: Indicates if email is for newsletter + :param full_width: Will make newsletter email appear with full width on screen + :param add_web_link: Will add web view link to newsletter email """ if not unsubscribe_method: unsubscribe_method = "/api/method/frappe.email.queue.unsubscribe" @@ -127,10 +130,15 @@ def send(recipients=None, sender=None, subject=None, message=None, text_content= if should_append_unsubscribe: unsubscribe_link = get_unsubscribe_message(unsubscribe_message, expose_recipients) email_text_context += unsubscribe_link.text + + web_link = None + if add_web_link and reference_doctype and reference_doctype == "Newsletter": + web_link = get_url(uri = "/newsletters/{0}".format(reference_name)) email_content = get_formatted_html(subject, message, email_account=email_account, header=header, - unsubscribe_link=unsubscribe_link) + unsubscribe_link=unsubscribe_link, web_link=web_link, + is_newsletter=is_newsletter, full_width=full_width) # add to queue add(recipients, sender, subject, diff --git a/frappe/templates/emails/email_footer.html b/frappe/templates/emails/email_footer.html index 4ad6cb23b5..4e12fbb92e 100644 --- a/frappe/templates/emails/email_footer.html +++ b/frappe/templates/emails/email_footer.html @@ -15,6 +15,14 @@ {% endif %} + {% if web_link %} +
+
+ Open in web +
+
+ {% endif %} +
diff --git a/frappe/templates/emails/standard.html b/frappe/templates/emails/standard.html index affabbc4c6..e1a5b483c5 100644 --- a/frappe/templates/emails/standard.html +++ b/frappe/templates/emails/standard.html @@ -12,7 +12,7 @@ + width="{% if header or (is_newsletter and not full_width) %}600{% else %}100%{% endif %}">