问题描述
我正在Google App Engine上托管一个项目,并为我的用户系统使用Django-allauth。
现在我只是使用以下设置在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 ='密码'
但我想使用GAE的Mail API,以便我可以使用所有可用的配额。
发送带有GAE API的电子邮件我可以这样做:
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)来连接自己的自定义机制。
但是我真的很想知道如何去做这个事情。
我放置覆盖的功能是否重要?
任何其他提示将不胜感激。
我的解决方案 / p>
我做了什么让Django-allauth电子邮件系统使用
在我的首页应用程序中创建一个文件auth.py:
来自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,请务必记住作为发件人
最后,如e4c5所指出,allauth必须知道这个覆盖存在,这是在settings.py
ACCOUNT_ADAPTER = home.auth.MyAccountAdapter'
你必须告诉django关于您的自定义适配器的说明,将以下行添加到settings.py
ACCOUNT_ADAPTER ='my_app.MyAccountAdapter'
小心使用正确的名称替换my_app
I'm working on a project hosted on Google App Engine, and using Django-allauth for my user system.
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'
But I would like to use GAE's Mail API instead, so that I can take use of all the quotas available.
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)
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.
My Solution
What I did to get Django-allauth email system to work with Google App Engine mail API
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)
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
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'
You have to tell django-allauth about your custom adapter by adding the following line to settings.py
ACCOUNT_ADAPTER = 'my_app.MyAccountAdapter'
taking care to replace my_app with the correct name
这篇关于使用Google App Enigne的Mail API进行django-allauth电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!