瀏覽代碼

Email footer (#3784)

* Add frappe.preview_email for faster feedback on email design

* Set Unsubscribe link color to text-muted

* error handling for header

* codacy fixes
version-14
Faris Ansari 8 年之前
committed by Rushabh Mehta
父節點
當前提交
1332710982
共有 4 個檔案被更改,包括 30 行新增3 行删除
  1. +12
    -2
      frappe/email/email_body.py
  2. +1
    -1
      frappe/email/queue.py
  3. +1
    -0
      frappe/public/build.json
  4. +16
    -0
      frappe/public/js/frappe/misc/preview_email.js

+ 12
- 2
frappe/email/email_body.py 查看文件

@@ -251,6 +251,16 @@ def get_formatted_html(subject, message, footer=None, print_html=None, email_acc
transformed_html = inline_style_in_html(sanitized_html)
return transformed_html

@frappe.whitelist()
def get_email_html(template, args, subject, header=None):
import json

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)

def inline_style_in_html(html):
''' Convert email.css and html to inline-styled html
'''
@@ -334,8 +344,6 @@ def get_footer(email_account, footer=None):
if email_account and email_account.footer:
footer += '<div style="margin: 15px auto;">{0}</div>'.format(email_account.footer)

footer += "<!--unsubscribe link here-->"

company_address = frappe.db.get_default("email_footer_address")

if company_address:
@@ -347,6 +355,8 @@ def get_footer(email_account, footer=None):
.format(x)
footer += "</table>"

footer += "<!--unsubscribe link here-->"

if not cint(frappe.db.get_default("disable_standard_email_footer")):
for default_mail_footer in frappe.get_hooks("default_mail_footer"):
footer += '<div style="margin: 15px auto;">{0}</div>'.format(default_mail_footer)


+ 1
- 1
frappe/email/queue.py 查看文件

@@ -236,7 +236,7 @@ def get_unsubscribe_message(unsubscribe_message, expose_recipients):
html = """<div style="margin: 15px auto; padding: 0px 7px; text-align: center; color: #8d99a6;">
<!--cc message-->
<p style="margin: 15px auto;">
<a href="<!--unsubscribe url-->" style="color: #8d99a6; text-decoration: underline;
<a href="<!--unsubscribe url-->" style="color: #8d99a6; text-decoration: underline;"
target="_blank">{unsubscribe_message}
</a>
</p>


+ 1
- 0
frappe/public/build.json 查看文件

@@ -132,6 +132,7 @@
"public/js/frappe/misc/help.js",
"public/js/frappe/misc/help_links.js",
"public/js/frappe/misc/address_and_contact.js",
"public/js/frappe/misc/preview_email.js",

"public/js/frappe/ui/upload.html",
"public/js/frappe/upload.js",


+ 16
- 0
frappe/public/js/frappe/misc/preview_email.js 查看文件

@@ -0,0 +1,16 @@
frappe.preview_email = function(template, args, header) {
frappe.call({
method: 'frappe.email.email_body.get_email_html',
args: {
subject: 'Test',
template,
args,
header
}
}).then((r) => {
var html = r.message;
html = html.replace(/embed=/, 'src=');
var d = frappe.msgprint(html);
d.$wrapper.find('.modal-dialog').css('width', '70%');
});
};

Loading…
取消
儲存