繁体   English   中英

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

[英]django rest-auth email confirmation with postmark

我已经了解了有关如何覆盖电子邮件模板的一些知识,但是它们似乎主要涉及创建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)

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

rest_auth只提供REST框架接口allauth

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

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

您可以通过在settings.py 配置中设置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 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM