emails: Fix some css not being applied to emails.

This commit places the email CSS into the `style` tag located in the
`head` section. This resolves the issue of being unable to apply
certain CSS styles that cannot be inlined, such as media queries and
pseudo-classes.
This commit is contained in:
Daniil Fadeev 2023-04-27 16:50:02 +07:00 committed by Tim Abbott
parent 521487f444
commit db37880d08
5 changed files with 9 additions and 8 deletions

View File

@ -147,8 +147,8 @@ p.digest_paragraph,
.sponsorship_request_link:hover, .sponsorship_request_link:hover,
.support_request_link:hover, .support_request_link:hover,
.email-preferences a:hover, .email-preferences a:hover,
.missed_message.no_content a:hover { .missed_message.no_content-explanation a:hover {
color: #434388; color: #434388 !important;
} }
.important { .important {

View File

@ -1,10 +1,12 @@
{% import 'zerver/emails/macros.html' as macros %} {% import 'zerver/emails/macros.html' as macros %}
{% import 'zerver/emails/email.css' as css_styles %}
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta name="viewport" content="width=device-width" /> <meta name="viewport" content="width=device-width" />
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<title>Zulip</title> <title>Zulip</title>
<style>{{css_styles}}</style>
</head> </head>
<body> <body>
<table border="0" cellpadding="0" cellspacing="0" class="body layout"> <table border="0" cellpadding="0" cellspacing="0" class="body layout">

View File

@ -1,10 +1,12 @@
{% import 'zerver/emails/macros.html' as macros %} {% import 'zerver/emails/macros.html' as macros %}
{% import 'zerver/emails/email.css' as css_styles %}
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta name="viewport" content="width=device-width" /> <meta name="viewport" content="width=device-width" />
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<title>Zulip</title> <title>Zulip</title>
<style>{{css_styles}}</style>
</head> </head>
<body> <body>
<table border="0" cellpadding="0" cellspacing="0" class="body layout"> <table border="0" cellpadding="0" cellspacing="0" class="body layout">

View File

@ -1,8 +1,10 @@
{% import 'zerver/emails/email.css' as css_styles %}
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<title>Zulip</title> <title>Zulip</title>
<style>{{css_styles}}</style>
</head> </head>
{% if has_preheader %} {% if has_preheader %}
<span style="display:none !important; <span style="display:none !important;

View File

@ -32,9 +32,6 @@ from zerver.models import EMAIL_TYPES, Realm, ScheduledEmail, UserProfile, get_u
from zproject.email_backends import EmailLogBackEnd, get_forward_address from zproject.email_backends import EmailLogBackEnd, get_forward_address
MAX_CONNECTION_TRIES = 3 MAX_CONNECTION_TRIES = 3
ZULIP_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../")
EMAIL_TEMPLATES_PATH = os.path.join(ZULIP_PATH, "templates", "zerver", "emails")
CSS_SOURCE_PATH = os.path.join(EMAIL_TEMPLATES_PATH, "email.css")
## Logging setup ## ## Logging setup ##
@ -43,9 +40,7 @@ log_to_file(logger, settings.EMAIL_LOG_PATH)
def get_inliner_instance() -> css_inline.CSSInliner: def get_inliner_instance() -> css_inline.CSSInliner:
with open(CSS_SOURCE_PATH) as file: return css_inline.CSSInliner()
content = file.read()
return css_inline.CSSInliner(extra_css=content)
class FromAddress: class FromAddress: