[英]django rest-auth email confirmation with postmark
I've seen a fair bit about how to override the email templates, but they seem to mostly involve creating HTML templates and overriding the file location. 我已经了解了有关如何覆盖电子邮件模板的一些知识,但是它们似乎主要涉及创建HTML模板和覆盖文件位置。
I'm using postmark's templating which involves sending a post request with the email variables. 我正在使用邮戳的模板,其中涉及发送带有电子邮件变量的邮寄请求。 I'm handling that with anymail, as shown below with a form that sends my customer service address an email:
我正在使用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)
My goal is to use postmark templates for the account confirmation & password reset emails also, but I'm having a hard time figuring out how to override the send methods. 我的目标是也将邮戳模板用于帐户确认和密码重置电子邮件,但是我很难弄清楚如何覆盖发送方法。
rest_auth
only provides the rest framework interface to allauth
. rest_auth
只提供REST框架接口allauth
。
You want to override allauth's emails, not rest_auth's. 您要覆盖allauth的电子邮件,而不是rest_auth的电子邮件。
allauth doc on sending email allauth.account.adapter.DefaultAccountAdapter.send_email()
关于发送电子邮件的
allauth.account.adapter.DefaultAccountAdapter.send_email()
文档allauth.account.adapter.DefaultAccountAdapter.send_email()
You can do this by setting the ACCOUNT_ADAPTER
in your settings.py configuration and subclassing the DefaultAccountAdapter
您可以通过在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.