[英]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
有人對這個問題有想法嗎? 它顯示在 Gmail 和 Outlook 中。 我已經檢查過 css 並且我認為它不會導致這個問題。
更新:我在這里附上了與內容相關的部分代碼:
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)
)
這種額外的間距通常是由僅設置html_content
引起的。 HTML 通常會帶有空格。 如果您還設置了text_content
,它將用於 email 預覽。 來自 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.