[英]Html email title spacing between the subject and the actual message python django
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 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.
它显示在 Gmail 和 Outlook 中。 I already checked css and I think it doesn't cause this problem.
我已经检查过 css 并且我认为它不会导致这个问题。
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_content
引起的。 HTML often will come with white space. HTML 通常会带有空格。 If you also set the
text_content
, this will be used instead for the email preview.如果您还设置了
text_content
,它将用于 email 预览。 An example from the django docs ( https://docs.djangoproject.com/en/3.1/topics/email/ ) which includes a text_content
:来自 django 文档( https://docs.djangoproject.com/en/3.1/topics/email/ )的示例,其中包括
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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.