【问题标题】:Email Template not being rendered properly by gmail and outlookgmail和outlook没有正确呈现电子邮件模板
【发布时间】:2019-09-13 20:59:58
【问题描述】:

我正在使用 django 发送电子邮件, 我有这个 django 模板:

<!DOCTYPE html>
<html lang="en" style="font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;width: 100%;height: 100%;margin: 0;">
<head>
    <meta charset="UTF-8" style="box-sizing: border-box;">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta http-equiv="Content-Type" content="text/html charset=UTF-8">
</head>
<body style="box-sizing: border-box;width: 100%;height: 100%;margin: 0;">
    <div class="main_container" style="box-sizing: border-box;background-color: #f9f9f9;padding: 0 15px;width: 100%;height: 100%;margin: 0;">
        <div class="container" style="box-sizing: border-box;display: grid;grid-template-rows: 100px minmax(100px, auto) 100px;align-content: center;max-width: 700px;margin: 0 auto;">
            <div class="header" style="box-sizing: border-box;">
                <img src="cid:mindr_icon" style="box-sizing: border-box;width: 90px;margin: 0 auto;display: block;">
            </div>
            <div class="content" style="box-sizing: border-box;background: #fff;border-radius: 15px;box-shadow: 0 0 10px #f3f3f3;color: #454c54;padding: 10px;">
                Test Email !
            </div>
            <div class="footer" style="box-sizing: border-box;font-size: 20px;text-align: center;">
                <div class="links_footer" style="box-sizing: border-box;display: grid;grid-template-columns: 1fr 1fr 1fr;grid-template-rows: 1fr;padding: 30px 20px 10px 20px;border-bottom: 1px solid rgba(0, 0, 0, .1);width: 80%;margin: 0 auto;">
                    <a href="#" style="box-sizing: border-box;text-decoration: none;color: #454c54;font-weight: 800;text-align: left;">PRICING</a>
                    <a href="#" style="box-sizing: border-box;text-decoration: none;color: #454c54;font-weight: 800;">HELP</a>
                    <a href="#" style="box-sizing: border-box;text-decoration: none;color: #454c54;font-weight: 800;text-align: right;">CONTACT</a>
                </div>
                <div class="social_footer" style="box-sizing: border-box;padding-top: 10px;display: grid;grid-template-columns: 18px 18px 18px;grid-auto-rows: 18px;grid-gap: 18px;width: 90px;justify-content:center;margin: 0 auto;">
                    <a href="#" class="social" style="box-sizing: border-box;text-decoration: none;color: #454c54;font-weight: 800;">
                        <img src="cid:fb_ico" style="box-sizing: border-box;width: 18px;">
                    </a>
                    <a href="#" class="social" style="box-sizing: border-box;text-decoration: none;color: #454c54;font-weight: 800;">
                        <img src="cid:tw_ico" style="box-sizing: border-box;width: 18px;">
                    </a>
                    <a href="#" class="social" style="box-sizing: border-box;text-decoration: none;color: #454c54;font-weight: 800;">
                        <img src="cid:in_ico" style="box-sizing: border-box;width: 18px;">
                    </a>
                </div>
                <div class="made_with_love" style="box-sizing: border-box;padding-top: 10px;font-size: 13px;font-weight: 800;color: #575858;word-spacing: 2px;width: 80%;margin: 0 auto;">Made with <span style="color: #e25555;box-sizing: border-box;">&#9829;</span> By ____ Team</div>
            </div>
        </div>
    </div>
</body>
</html>

我的问题是大多数电子邮件客户端没有正确呈现 HTML,所以我想知道我可以更改什么来解决这个问题。

到目前为止,我已经测试过 Gmail、Outlook 和 MailSpring,唯一能正确显示电子邮件的电子邮件客户端是 MailSpring

谢谢!

Mailspring:

Gmail:

展望:

【问题讨论】:

  • 移除 display: grid 并尝试其他显示属性。
  • 我试过 flex,但也没用
  • 尝试内联块

标签: html css email templates html-email


【解决方案1】:

邮件模板不支持Display: gridDisplay: flex。试试这个:

<!DOCTYPE html>
<html lang="en" style="font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;width: 100%;height: 100%;margin: 0;">
<head>
    <meta charset="UTF-8" style="box-sizing: border-box;">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta http-equiv="Content-Type" content="text/html charset=UTF-8">
</head>
<body style="box-sizing: border-box;width: 100%;height: 100%;margin: 0;">
    <div class="main_container" style="box-sizing: border-box;background-color: #f9f9f9;padding: 0 15px;width: 100%;height: 100%;margin: 0;">
        <div class="container" style="box-sizing: border-box;display: grid;grid-template-rows: 100px minmax(100px, auto) 100px;align-content: center;max-width: 700px;margin: 0 auto;">
            <div class="header" style="box-sizing: border-box;">
                <img src="cid:mindr_icon" style="box-sizing: border-box;width: 90px;margin: 0 auto;display: block;">
            </div>
            <div class="content" style="box-sizing: border-box;background: #fff;border-radius: 15px;box-shadow: 0 0 10px #f3f3f3;color: #454c54;padding: 10px;">
                Test Email !
            </div>
            <div class="footer" style="box-sizing: border-box;font-size: 20px;text-align: center;">
                <div class="links_footer" style="box-sizing: border-box;display: grid;grid-template-columns: 1fr 1fr 1fr;grid-template-rows: 1fr;padding: 30px 20px 10px 20px;border-bottom: 1px solid rgba(0, 0, 0, .1);width: 80%;margin: 0 auto;">
                    <a href="#" style="box-sizing: border-box;text-decoration: none;color: #454c54;font-weight: 800;text-align: left;">PRICING</a>
                    <a href="#" style="box-sizing: border-box;text-decoration: none;color: #454c54;font-weight: 800;">HELP</a>
                    <a href="#" style="box-sizing: border-box;text-decoration: none;color: #454c54;font-weight: 800;text-align: right;">CONTACT</a>
                </div>
                <div class="social_footer" style="box-sizing: border-box;padding-top: 10px;display: inline-block;">
                    <a href="#" class="social" style="display: inline-block; width: 18px; margin: 0 6px; box-sizing: border-box;text-decoration: none;color: #454c54;font-weight: 800;">
                        <img src="cid:fb_ico" style="box-sizing: border-box;width: 18px;">
                    </a>
                    <a href="#" class="social" style="display: inline-block; width: 18px; margin: 0 6px; box-sizing: border-box;text-decoration: none;color: #454c54;font-weight: 800;">
                        <img src="cid:tw_ico" style="box-sizing: border-box;width: 18px;">
                    </a>
                    <a href="#" class="social" style="display: inline-block; width: 18px; margin: 0 6px; box-sizing: border-box;text-decoration: none;color: #454c54;font-weight: 800;">
                        <img src="cid:in_ico" style="box-sizing: border-box;width: 18px;">
                    </a>
                </div>
                <div class="made_with_love" style="box-sizing: border-box;padding-top: 10px;font-size: 13px;font-weight: 800;color: #575858;word-spacing: 2px;width: 80%;margin: 0 auto;">Made with <span style="color: #e25555;box-sizing: border-box;">&#9829;</span> By ____ Team</div>
            </div>
        </div>
    </div>
</body>
</html>

【讨论】:

    【解决方案2】:

    我相信让模板在所有电子邮件客户端上显示相似的最佳方法是使用表格和内联 CSS。但是,并非所有电子邮件客户端都支持所有 CSS 属性,因此您可能需要检查哪些支持正常,哪些不支持。

    这里是所有属性及其支持的列表:https://www.campaignmonitor.com/css/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-24
      • 2018-12-19
      • 1970-01-01
      • 1970-01-01
      • 2020-01-06
      • 1970-01-01
      • 2022-01-03
      • 1970-01-01
      相关资源
      最近更新 更多