I am trying to send a mail through HTML email. Everything is working perfectly, but the inline css of html file is not getting rendered in actual email. 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!")
Here my html file :
<html>
<head>
</head>
<body>
<div style="backgound-color:red;position:relative;width:100%;text-align:center;">Email Verification</div>
Hi {{ user.username }},
</body>
Please help!
The red background is being skipped because of the spelling: backgound-color
vs background-color
.
Also did you try different email clients - HTML email is very much it's own art.