本文介绍了使用Google App Engine的Mail API处理django-allauth电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个托管在Google App Engine上的项目,并将Django-allauth用于我的用户系统。

I'm working on a project hosted on Google App Engine, and using Django-allauth for my user system.

现在我只使用以下内容在settings.py

Right now I'm just using the following setup in settings.py

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = DEFAULT_FROM_EMAIL = '[email protected]'
EMAIL_HOST_PASSWORD = 'password'

但是我想改用GAE的Mail API,以便我可以利用所有可用的配额。

But I would like to use GAE's Mail API instead, so that I can take use of all the quotas available.

使用GAE的API发送电子邮件我可以这样做:

To send an email with GAE's API I can do as follows:

sender_address = "[email protected]"
subject = "Subject"
body = "Body."
user_address = "[email protected]"
mail.send_mail(sender_address, user_address, subject, body)

据我从,我可以通过覆盖帐户适配器的send_mail方法(allauth.account.adapter.DefaultAccountAdapter)来建立自己的自定义机制。

As I understand it from the allauth documentation, I can "hook up your own custom mechanism by overriding the send_mail method of the account adapter (allauth.account.adapter.DefaultAccountAdapter)."

但是我真的对如何执行此操作感到困惑。

But I'm really confusing about how to go about doing this.

在放置覆盖函数的位置上有关系吗?

Does it matter where I place the overridden function?

任何其他提示将不胜感激。

Any additional tips would be greatly appreciated.

我的解决方案

我为使Django-allauth电子邮件系统与

What I did to get Django-allauth email system to work with Google App Engine mail API

在家庭应用中创建文件auth.py:

Created a file auth.py in my 'Home' app:

from allauth.account.adapter import DefaultAccountAdapter
from google.appengine.api import mail


class MyAccountAdapter(DefaultAccountAdapter):

    def send_mail(self, template_prefix, email, context):
        msg = self.render_mail(template_prefix, email, context)

        sender_address = "[email protected]"
        subject = msg.subject
        body = msg.body
        user_address = email
        mail.send_mail(sender_address, user_address, subject, body)

要使用您的电子邮件作为GAE邮件API的发件人,请务必记住作为发件人

In order to use your email as sender with GAE's mail API, it is important to remember to authorize the email as a sender

最后,正如e4c5所指出的,allauth具有知道存在此覆盖,在settings.py

Lastly, as e4c5 pointed out, allauth has to know that this override exists, which is done as so in settings.py

ACCOUNT_ADAPTER = 'home.auth.MyAccountAdapter'


推荐答案

您必须告诉django-allauth关于您的自定义适配器,方法是将以下行添加到settings.py

You have to tell django-allauth about your custom adapter by adding the following line to settings.py

ACCOUNT_ADAPTER = 'my_app.MyAccountAdapter'

注意用正确的名称替换my_app

taking care to replace my_app with the correct name

这篇关于使用Google App Engine的Mail API处理django-allauth电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 05:38