Django 2,Python 3.
使用Django默认身份验证发送用户注册电子邮件。发送的电子邮件包含损坏的html。
包含3D,每个属性都有等号。
style=3D"margin:
包含**=**,每一个新的开始行。
padd=
****ing-top:20px;
示例编码:
<div style="padding: 40px; background: #fff;">
<table style="width: 100%;" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td style="border-bottom:1px solid #f6f6f6;">
<h1 style="font-size:14px; font-family:arial; margin:0px; font-weight:bold;">{% trans 'Greetings!,' %}</h1>
<p style="margin-top:0px; color:#bbbbbb;">{% trans 'Here are your account activation instructions.' %}</p>
</td>
</tr>
<tr>
<td style="padding:10px 0 30px 0;">
<p>{% trans 'Thank you for joining us.' %}</p>
<p>{% trans 'To activate your profile, please follow this link:' %}</p>
<center>
<a href="{{ uri }}" style="display: inline-block; padding: 11px 30px; margin: 20px 0px 30px; font-size: 15px; color: #fff; background: #4fc3f7; border-radius: 60px; text-decoration:none;">{% trans 'Activate Profile' %}</a>
</center>
<b>- {% trans 'Thanks (project team)' %}</b> </td>
</tr>
<tr>
<td style="border-top:1px solid #f6f6f6; padding-top:20px; color:#777">{% trans 'If the button above does not work, try copying and pasting the URL into your browser. If you continue to have problems, please feel free to contact us at info@project.com' %}</td>
</tr>
</tbody>
</table>
</div>
生成的HTML模板:
<div style=3D"padding: 40px; background: #fff;">
<table style=3D"width: 100%;" cellspacing=3D"0" cellpadding=
=3D"0" border=3D"0">
<tbody>
<tr>
<td style=3D"border-bottom:1px solid #f6f6f6;">
<h1 style=3D"font-size:14px; font-family:ar=
ial; margin:0px; font-weight:bold;">Greetings!,</h1>
<p style=3D"margin-top:0px; color:#bbbbbb;"=
>Here are your account activation instructions.</p>
</td>
</tr>
<tr>
<td style=3D"padding:10px 0 30px 0;">
<p>Thank you for joining us.</p>
<p>To activate your profile, please follow =
this link:</p>
<center>
<a href=3D"http://localhost:8000/accoun=
ts/activate/uyi90WsYyvLKmn4wwwqq/" style=3D"display: inline-block; padding:=
11px 30px; margin: 20px 0px 30px; font-size: 15px; color: #fff; background=
: #4fc3f7; border-radius: 60px; text-decoration:none;">Activate Profile</a>
</center>
<b>- Thanks (project team)</b> </td>
</tr>
<tr>
<td style=3D"border-top:1px solid #f6f6f6; padd=
ing-top:20px; color:#777">If the button above does not work, try copying an=
d pasting the URL into your browser. If you continue to have problems, plea=
se feel free to contact us at info@project.com</td>
</tr>
</tbody>
</table>
</div>
请帮助解决/确定问题。
1条答案
按热度按时间czq61nw11#
我在运行测试时遇到了类似的问题,我想分享一下这个问题以及如何处理它
在测试期间,Django将电子邮件后端设置为locmem,我们使用
django.core.mail.outbox
返回一个包含已发送电子邮件的数组来测试它们的内容因此,考虑一封已发送的电子邮件作为这样的数组的第一个元素:
检查内容并获得清晰的HTML:
获取Quoted-Printable编码(使用=3D):