我有一个使用 Djoser 进行身份验证的 DRF 项目。计划是覆盖 Djoser 的默认激活电子邮件并发送一些 HTML 模板电子邮件。这是我所拥有的:
# settings.py
DJOSER = {
"SEND_ACTIVATION_EMAIL": True,
"ACTIVATION_URL": "activate/{uid}/{token}",
"EMAIL": {"activation": "base.emails.ActivationEmail"},
}
# base/emails
from django.contrib.auth.tokens import default_token_generator
from djoser import email, utils
from djoser.conf import settings
class ActivationEmail(email.ActivationEmail):
template_name = "emails/activation.html"
def get_context_data(self):
# ActivationEmail can be deleted
context = super().get_context_data()
user = context.get("user")
context["first_name"] = user.first_name
context["uid"] = utils.encode_uid(user.pk)
context["token"] = default_token_generator.make_token(user)
context["url"] = settings.ACTIVATION_URL.format(**context)
return context
# templates/emails/activation.html
{% extends "emails/base.html" %}
{% load static %}
{% block subject %}Account Activation on Dummy{% endblock %}
{% block heading %}
Account Activation
{% endblock %}
{% block content %}
You're receiving this email because you need to finish activation process.
Please click on the button below to activate your account:
<br><br><br>
<a
href="{{ url }}"
target="_blank"
style="
text-decoration: none;
font-family: lato, 'helvetica neue', helvetica, arial, sans-serif;
font-size: 20px;
color: #fff;
background-color: #0b913a;
padding: 10px 25px;
border-radius: 5px;
"
>Activate</a
>
<br><br><br>
Best Regards,<br>
The DUMMY Team
<br><br>
<p
style="
margin: 0;
-webkit-text-size-adjust: none;
-ms-text-size-adjust: none;
mso-line-height-rule: exactly;
font-size: 14px;
font-family: lato, 'helvetica neue', helvetica, arial, sans-serif;
line-height: 21px;
color: #666666;
"
>
If you did not make this request, reply to this email or write to info@dummy.com so we can
look into a possible attempt to impersonate you.
</p>
{% endblock %}
一切似乎都正确,但电子邮件没有发送。我检查收件箱,什么也没看到。但是,当我删除指向自定义电子邮件的删除 EMAIL 设置时,它会发送默认的 Djoser 激活电子邮件。怎么了?