We are trying to implement the email function using python django and it shows extra spaces in the header in the mail box like the following screenshots
Does anyone have ideas about this issue? It shows in Gmail and also Outlook. I already checked css and I think it doesn't cause this problem.
Update: I attached the part of code related to the content here:
encrypted_text = str(encrypt(SECRET_KEY, text + ':' + confirmation_str) ,'utf-8')
message = Mail(
from_email=from,
to_emails=to,
subject=subject,
html_content=email_template.getEmailTemplate(encrypted_text)
)
This extra spacing is usually caused by setting only the html_content
. HTML often will come with white space. If you also set the text_content
, this will be used instead for the email preview. An example from the django docs ( https://docs.djangoproject.com/en/3.1/topics/email/ ) which includes a text_content
:
subject, from_email, to = 'hello', 'from@example.com', 'to@example.com'
text_content = 'This is an important message.'
html_content = '<p>This is an <strong>important</strong> message.</p>'
msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
msg.attach_alternative(html_content, "text/html")
msg.send()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.