Django的html电子邮件内联CSS无法工作

2024-09-29 21:50:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试通过HTML电子邮件发送邮件。一切都运行得很好,但html文件的内联css并没有在实际的电子邮件中呈现出来。 视图.py

        subject = 'Activate Your Account.'
        htmly     = get_template('account_activation_email.html')

        d = { 'user': user, 'domain':current_site.domain, 'uid':urlsafe_base64_encode(force_bytes(user.pk)), 'token': account_activation_token.make_token(user)}
        text_content = ""
        html_content = htmly.render(d)
        msg = EmailMultiAlternatives(subject, text_content, '', [user.email])
        msg.attach_alternative(html_content, "text/html")
        try:
            msg.send()
        except BadHeaderError:
            print("Error while sending email!")

这里是我的html文件:

<html>
<head>
</head>
<body>
    <div style="backgound-color:red;position:relative;width:100%;text-align:center;">Email Verification</div>
    Hi {{ user.username }},
</body>

请帮帮我!你知道吗


Tags: 文件texttokenemaildomainhtmlbodymsg

热门问题