diff --git a/frappe/email/email_body.py b/frappe/email/email_body.py
index 80005eef1d..a3f54659e2 100755
--- a/frappe/email/email_body.py
+++ b/frappe/email/email_body.py
@@ -233,7 +233,8 @@ class EMail:
self.make()
return self.msg_root.as_string()
-def get_formatted_html(subject, message, footer=None, print_html=None, email_account=None, header=None):
+def get_formatted_html(subject, message, footer=None, print_html=None,
+ email_account=None, header=None, unsubscribe_link=None):
if not email_account:
email_account = get_outgoing_email_account(False)
@@ -247,9 +248,13 @@ def get_formatted_html(subject, message, footer=None, print_html=None, email_acc
"subject": subject
})
- sanitized_html = scrub_urls(rendered_email)
- transformed_html = inline_style_in_html(sanitized_html)
- return transformed_html
+ html = scrub_urls(rendered_email)
+
+ if unsubscribe_link:
+ html = html.replace("", unsubscribe_link.html)
+
+ html = inline_style_in_html(html)
+ return html
@frappe.whitelist()
def get_email_html(template, args, subject, header=None):
@@ -341,25 +346,20 @@ def get_footer(email_account, footer=None):
"""append a footer (signature)"""
footer = footer or ""
+ args = {}
+
if email_account and email_account.footer:
- footer += '
{0}
'.format(email_account.footer)
+ args.update({'email_account_footer': email_account.footer})
company_address = frappe.db.get_default("email_footer_address")
if company_address:
- company_address = company_address.splitlines(True)
- footer += ''
- footer += ' |
'
- for x in company_address:
- footer += '{0} |
'\
- .format(x)
- footer += "
"
-
- footer += ""
+ args.update({'company_address': company_address})
if not cint(frappe.db.get_default("disable_standard_email_footer")):
- for default_mail_footer in frappe.get_hooks("default_mail_footer"):
- footer += '{0}
'.format(default_mail_footer)
+ args.update({'default_mail_footer': frappe.get_hooks('default_mail_footer')})
+
+ footer += frappe.utils.jinja.get_email_from_template('email_footer', args)[0]
return footer
diff --git a/frappe/email/queue.py b/frappe/email/queue.py
index 44a987fb81..87056e1d01 100755
--- a/frappe/email/queue.py
+++ b/frappe/email/queue.py
@@ -75,8 +75,6 @@ def send(recipients=None, sender=None, subject=None, message=None, text_content=
except HTMLParser.HTMLParseError:
text_content = "See html attachment"
- formatted = get_formatted_html(subject, message, email_account=email_account, header=header)
-
if reference_doctype and reference_name:
unsubscribed = [d.email for d in frappe.db.get_all("Email Unsubscribe", "email",
{"reference_doctype": reference_doctype, "reference_name": reference_name})]
@@ -88,14 +86,22 @@ def send(recipients=None, sender=None, subject=None, message=None, text_content=
recipients = [r for r in list(set(recipients)) if r and r not in unsubscribed]
- email_content = formatted
email_text_context = text_content
- if add_unsubscribe_link and reference_doctype and (unsubscribe_message or reference_doctype=="Newsletter") and add_unsubscribe_link==1:
+ should_append_unsubscribe = (add_unsubscribe_link
+ and reference_doctype
+ and (unsubscribe_message or reference_doctype=="Newsletter")
+ and add_unsubscribe_link==1)
+
+ unsubscribe_link = None
+ if should_append_unsubscribe or True:
unsubscribe_link = get_unsubscribe_message(unsubscribe_message, expose_recipients)
- email_content = email_content.replace("", unsubscribe_link.html)
email_text_context += unsubscribe_link.text
+ email_content = get_formatted_html(subject, message,
+ email_account=email_account, header=header,
+ unsubscribe_link=unsubscribe_link)
+
# add to queue
add(recipients, sender, subject,
formatted=email_content,
@@ -230,17 +236,21 @@ def get_emails_sent_this_month():
status='Sent' and MONTH(creation)=MONTH(CURDATE())""")[0][0]
def get_unsubscribe_message(unsubscribe_message, expose_recipients):
- if not unsubscribe_message:
- unsubscribe_message = _("Unsubscribe from this list")
+ if unsubscribe_message:
+ unsubscribe_html = '''{0}'''.format(unsubscribe_message)
+ else:
+ unsubscribe_link = '''{0}'''.format(_('Unsubscribe'))
+ unsubscribe_html = _("{0} to stop receiving emails of this type").format(unsubscribe_link)
- html = """
+ html = """
""".format(unsubscribe_message=unsubscribe_message)
+
+ {0}
+
+
""".format(unsubscribe_html)
+
if expose_recipients == "footer":
text = "\n"
else:
diff --git a/frappe/public/css/email.css b/frappe/public/css/email.css
index 57b2033d49..4e9dfbaa6e 100644
--- a/frappe/public/css/email.css
+++ b/frappe/public/css/email.css
@@ -48,6 +48,16 @@ hr {
.body-table.has-header .email-footer {
border-top: none;
}
+.email-footer-container {
+ margin-top: 10px;
+}
+.email-footer-container > div:not(:last-child) {
+ margin-bottom: 5px;
+}
+.email-unsubscribe a {
+ color: #8D99A6;
+ text-decoration: underline;
+}
.btn {
text-decoration: none;
padding: 7px 10px;
diff --git a/frappe/public/less/email.less b/frappe/public/less/email.less
index 640c300daa..f07107891a 100644
--- a/frappe/public/less/email.less
+++ b/frappe/public/less/email.less
@@ -63,6 +63,19 @@ hr {
}
}
+.email-footer-container {
+ margin-top: 10px;
+
+ & > div:not(:last-child) {
+ margin-bottom: 5px;
+ }
+}
+
+.email-unsubscribe a {
+ color: @text-muted;
+ text-decoration: underline;
+}
+
.btn {
text-decoration: none;
padding: 7px 10px;
diff --git a/frappe/templates/emails/email_footer.html b/frappe/templates/emails/email_footer.html
new file mode 100644
index 0000000000..5352d817d5
--- /dev/null
+++ b/frappe/templates/emails/email_footer.html
@@ -0,0 +1,29 @@
+
\ No newline at end of file