django rest-auth带有邮戳的电子邮件确认

时间:2019-09-07 00:06:12

标签: django django-rest-framework django-rest-auth postmark django-anymail

我已经了解了有关如何覆盖电子邮件模板的一些信息,但是它们似乎主要涉及创建HTML模板和覆盖文件位置。

我正在使用邮戳的模板,该模板涉及发送带有电子邮件变量的邮寄请求。我正在使用anymail进行处理,如下所示,该表单通过向客户服务地址发送电子邮件的表格进行显示:

class PartnerContact(APIView):
    """Sends email to Partners@***.com"""

    @authentication_classes([])
    @permission_classes([])
    def post(self, request):
        """Sends Form Data"""

        print("PartnerContact data", request.data)

        status_code = status.HTTP_400_BAD_REQUEST

        msg = EmailMessage(
            from_email='Partners@***.com',
            to=['Partners@***.com'],
            reply_to=[request.data['email']]
        )

        msg.template_id = ***

        logo = attach_inline_image_file(msg, finders.find("***.png"))

        msg.merge_global_data = { **{**request.data, **{"logo":logo} } }

        # <img alt="Logo" src="cid:{logo_cid}">
        msg.send()
        status_code = status.HTTP_200_OK

        return Response(status=status_code)

我的目标是也将邮戳模板用于帐户确认和密码重置电子邮件,但是我很难确定如何覆盖发送方法。

1 个答案:

答案 0 :(得分:0)

rest_auth仅提供allauth的其余框架接口。

您要覆盖allauth的电子邮件,而不是rest_auth的电子邮件。

有关发送电子邮件allauth.account.adapter.DefaultAccountAdapter.send_email()的allauth文档

您可以通过在settings.py configuration中设置ACCOUNT_ADAPTER并为DefaultAccountAdapter子类化

from allauth.account.adapter import DefaultAccountAdapter

CustomAccountAdapter(DefaultAccountAdapter):
    def send_mail(self, template_prefix, email, context):
        # handle send mail the way you want to
        pass