Gmail not rendering email with html breaks properly when sent from Django
I'm currently using Django to send an email to a user who has forgotten
their password. All other email clients render the email properly with the
breaks. However Gmail doesn't seem to care about the html and it squishes
all the text together.
Here's what the email looks when rendered in hotmail:
Hello Bob,
You are receiving this email because you have (or someone pretending to be
you has) requested a new password to be sent for your account. If you did
not request this email then you can let us know at support@mailapp.com.
To reset your password, enter the temporary password below to login.
TEMPORARY PASSWORD: seBDTZK4cc
Once you are logged in, you can change your password in the "Edit Profile"
option under "Account" in Settings.
-The Mail App Team
However in gmail, it looks like this!:
Hello Bob,You are receiving this email because you have (or someone
pretending to be you has) requested a new password to be sent for your
account. If you did not request this email then you can let us know at
support@mailapp.com.To reset your password, enter the temporary password
below to login.TEMPORARY PASSWORD: seBDTZK4ccOnce you are logged in, you
can change your password in the "Edit Profile" option under "Account" in
Settings.-The Mail App Team
This is confusing users who have a gmail account because the temporary
password is being combined with the next sentence!
Here is the code from Django that I am using to send the emails:
def resetpassword(request):
data = json.loads(request.raw_post_data)
requestusername = data['username']
requestemail = data['email']
if User.objects.filter(username = requestusername).exists():
user_who_forgot_password = User.objects.get(username =
requestusername)
if user_who_forgot_password.email == requestemail:
password = User.objects.make_random_password()
user_who_forgot_password.set_password(password)
user_who_forgot_password.save()
email = EmailMessage('Password Reset On Mail App', 'Hello
%s,</br></br>You are receiving this email because you have (or
someone pretending to be you has) requested a new password to
be sent for your account. If you did not request this email
then you can let us know at support@mailapp.com.</br></br>To
reset your password, enter the temporary password below to
login.</br></br><b>TEMPORARY PASSWORD:</b> %s</br></br>Once
you are logged in, you can change your password in the "Edit
Profile" option under "Account" in Settings.</br></br>-The
MailApp Team' % (user_who_forgot_password.username, password),
to = ['{email}'.format(email=requestemail,)])
email.content_subtype = "html"
email.send()
print 'Password Email Sent'
return HttpResponse("Success")
else:
return HttpResponse("No email found")
else:
return HttpResponse("No username found")
How can I fix it so that it can be rendered in Gmail in such a way that it
is displayed properly like Hotmail?
No comments:
Post a Comment