我正在尝试通过HTML电子邮件发送邮件。一切都运行良好,但是html文件的内联css没有在实际的电子邮件中呈现。views.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>
请帮忙!
由于拼写,红色背景被跳过:backgound-color
vs background-color
。
你也尝试了不同的电子邮件客户端 - HTML电子邮件是它自己的艺术。