diff --git a/frappe/__init__.py b/frappe/__init__.py index 59edafa891..7367c30308 100644 --- a/frappe/__init__.py +++ b/frappe/__init__.py @@ -466,7 +466,7 @@ def sendmail(recipients=[], sender="", subject="No Subject", message="No Message attachments=None, content=None, doctype=None, name=None, reply_to=None, cc=[], bcc=[], message_id=None, in_reply_to=None, send_after=None, expose_recipients=None, send_priority=1, communication=None, retry=1, now=None, read_receipt=None, is_notification=False, - inline_images=None, template=None, args=None, header=None, print_letterhead=False): + inline_images=None, template=None, args=None, header=None, print_letterhead=False, with_container=False): """Send email using user's default **Email Account** or global default **Email Account**. @@ -492,6 +492,7 @@ def sendmail(recipients=[], sender="", subject="No Subject", message="No Message :param template: Name of html template from templates/emails folder :param args: Arguments for rendering the template :param header: Append header in email + :param with_container: Wraps email inside a styled container """ text_content = None if template: @@ -514,7 +515,7 @@ def sendmail(recipients=[], sender="", subject="No Subject", message="No Message attachments=attachments, reply_to=reply_to, cc=cc, bcc=bcc, message_id=message_id, in_reply_to=in_reply_to, send_after=send_after, expose_recipients=expose_recipients, send_priority=send_priority, communication=communication, now=now, read_receipt=read_receipt, is_notification=is_notification, - inline_images=inline_images, header=header, print_letterhead=print_letterhead) + inline_images=inline_images, header=header, print_letterhead=print_letterhead, with_container=False) whitelisted = [] guest_methods = [] diff --git a/frappe/email/email_body.py b/frappe/email/email_body.py index 59a504b40d..8d2cab918a 100755 --- a/frappe/email/email_body.py +++ b/frappe/email/email_body.py @@ -250,12 +250,13 @@ 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, with_container=False): if not email_account: email_account = get_outgoing_email_account(False, sender=sender) rendered_email = frappe.get_template("templates/emails/standard.html").render({ - "brand_logo": get_app_logo(), + "brand_logo": get_brand_logo(), + "with_container": with_container, "site_url": get_url(), "header": get_header(header), "content": message, @@ -275,14 +276,14 @@ def get_formatted_html(subject, message, footer=None, print_html=None, return html @frappe.whitelist() -def get_email_html(template, args, subject, header=None): +def get_email_html(template, args, subject, header=None, with_container=False): import json - + with_container = cint(with_container) args = json.loads(args) if header and header.startswith('['): header = json.loads(header) email = frappe.utils.jinja.get_email_from_template(template, args) - return get_formatted_html(subject, email[0], header=header) + return get_formatted_html(subject, email[0], header=header, with_container=with_container) def inline_style_in_html(html): ''' Convert email.css and html to inline-styled html @@ -369,10 +370,10 @@ def get_footer(email_account, footer=None): if email_account and email_account.footer: args.update({'email_account_footer': email_account.footer}) - company_address = frappe.db.get_default("email_footer_address") + sender_address = frappe.db.get_default("email_footer_address") - if company_address: - args.update({'company_address': company_address}) + if sender_address: + args.update({'sender_address': sender_address}) if not cint(frappe.db.get_default("disable_standard_email_footer")): args.update({'default_mail_footer': frappe.get_hooks('default_mail_footer')}) @@ -470,3 +471,6 @@ def get_header(header=None): def sanitize_email_header(str): return str.replace('\r', '').replace('\n', '') + +def get_brand_logo(): + return get_app_logo() \ No newline at end of file diff --git a/frappe/email/queue.py b/frappe/email/queue.py index f780aebdc1..2aff04edc9 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, with_container=False): """Add email to sending queue (Email Queue) :param recipients: List of recipients. @@ -48,6 +48,7 @@ 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 with_container: Wraps email inside styled container """ if not unsubscribe_method: unsubscribe_method = "/api/method/frappe.email.queue.unsubscribe" @@ -130,7 +131,7 @@ def send(recipients=None, sender=None, subject=None, message=None, text_content= email_content = get_formatted_html(subject, message, email_account=email_account, header=header, - unsubscribe_link=unsubscribe_link) + unsubscribe_link=unsubscribe_link, with_container=with_container) # add to queue add(recipients, sender, subject, diff --git a/frappe/public/js/frappe/utils/preview_email.js b/frappe/public/js/frappe/utils/preview_email.js index bc628644f6..ef3991069a 100644 --- a/frappe/public/js/frappe/utils/preview_email.js +++ b/frappe/public/js/frappe/utils/preview_email.js @@ -1,4 +1,4 @@ -frappe.preview_email = function(template, args, header, only_html=false) { +frappe.preview_email = function(template, args, header, with_container=false, only_html=false) { return frappe .call({ method: 'frappe.email.email_body.get_email_html', @@ -6,7 +6,8 @@ frappe.preview_email = function(template, args, header, only_html=false) { subject: 'Test', template, args, - header + header, + with_container } }) .then(r => { diff --git a/frappe/public/scss/email.scss b/frappe/public/scss/email.scss index da23e259a2..2630f1fe8e 100644 --- a/frappe/public/scss/email.scss +++ b/frappe/public/scss/email.scss @@ -52,7 +52,6 @@ hr { .body-table { font-family: $font-stack; - background-color: $gray-100; border-collapse: collapse; table-layout: fixed; margin: 0 auto; @@ -60,7 +59,6 @@ hr { height: 100% !important; width: 100% !important; font-weight: normal; - color: $text-color; font-family: $font-stack; font-size: 14px; line-height: 1.4; @@ -70,35 +68,7 @@ hr { } .body-content { - padding: 60px 40px; - } -} - -.email-container { - max-width: 600px; - border-spacing: 0; - padding: 30px; - border-radius: $border-radius-lg; - overflow: hidden; - background-color: white; - .email-body > tr { - border-collapse: collapse; - border-bottom: none; - } - .brand-logo { - margin: auto; - text-align: center; - border: 0; - outline: none; - text-decoration: none; - max-height: 40px; - width: auto; - } -} - -@media only screen and (max-width: 600px) { - .email-container { - width: 90%; + padding: 20px 0; } } @@ -118,12 +88,11 @@ hr { } .email-footer { - font-size: 13px; + font-size: 12px; line-height: 20px; } .email-header { - .brand-image { width: 24px; height: 24px; @@ -137,10 +106,36 @@ hr { font-weight: 600; } -.body-table.has-header { - .email-body { - border-radius: 0 0 4px 4px; - border-top: none; +.body-table.with-container { + background-color: $gray-100; + color: $text-color; + .body-content { + padding: 60px 40px; + } + .email-container { + max-width: 600px; + border-spacing: 0; + padding: 30px; + border-radius: $border-radius-lg; + overflow: hidden; + background-color: white; + .email-body { + border-radius: 0 0 4px 4px; + border-top: none; + tr { + border-collapse: collapse; + border-bottom: none; + } + } + .brand-logo { + margin: auto; + text-align: center; + border: 0; + outline: none; + text-decoration: none; + max-height: 40px; + width: auto; + } } .email-footer { @@ -148,8 +143,14 @@ hr { } } +@media only screen and (max-width: 600px) { + .body-table.with-container .email-container { + width: 90%; + } +} + .email-footer-container { - margin-top: 40px; + margin-top: 60px; & > div:not(:last-child) { margin-bottom: 5px; diff --git a/frappe/social/doctype/energy_point_log/energy_point_log.py b/frappe/social/doctype/energy_point_log/energy_point_log.py index 3fc8b8cbfe..21a0e24598 100644 --- a/frappe/social/doctype/energy_point_log/energy_point_log.py +++ b/frappe/social/doctype/energy_point_log/energy_point_log.py @@ -322,15 +322,16 @@ def send_summary(timespan): all_users = [user.email for user in get_enabled_system_users()] frappe.sendmail( - subject='{} energy points summary'.format(timespan), - recipients=all_users, - template="energy_points_summary", - args={ + subject = '{} energy points summary'.format(timespan), + recipients = all_users, + template = "energy_points_summary", + args = { 'top_performer': user_points[0], 'top_reviewer': max(user_points, key=lambda x:x['given_points']), 'standings': user_points[:10], # top 10 - 'footer_message': get_footer_message(timespan).format(from_date, to_date) - } + 'footer_message': get_footer_message(timespan).format(from_date, to_date), + }, + with_container = 1 ) def get_footer_message(timespan): diff --git a/frappe/templates/emails/email_footer.html b/frappe/templates/emails/email_footer.html index 4ad6cb23b5..da6cab5f35 100644 --- a/frappe/templates/emails/email_footer.html +++ b/frappe/templates/emails/email_footer.html @@ -6,10 +6,10 @@ {% endif %} - - {% if company_address %} -
- 🏆 {{ frappe.get_fullname(top_performer.user) }} - {{ _('gained {0} points').format(frappe.utils.cint(top_performer.energy_points)) }} + {{ avatar(top_performer.user) }} + {{ + _('{0} gained {1} points').format( + frappe.get_fullname(top_performer.user), + frappe.utils.cint(top_performer.energy_points) + ) + }}
{% endif %} {% if top_reviewer.given_points %} -- ❤️ {{ frappe.get_fullname(top_reviewer.user) }} - {{ _('gave {0} points').format(frappe.utils.cint(top_reviewer.given_points)) }} + {{ avatar(top_reviewer.user) }} + {{ + _('{0} gave {1} points').format( + frappe.get_fullname(top_reviewer.user), + frappe.utils.cint(top_reviewer.given_points) + ) + }}
{% endif %} diff --git a/frappe/templates/emails/standard.html b/frappe/templates/emails/standard.html index 830dc004c8..d9d53e43d1 100644 --- a/frappe/templates/emails/standard.html +++ b/frappe/templates/emails/standard.html @@ -8,11 +8,12 @@ -
|