问题描述
如何向使用django应用程序注册的用户(使用django-allauth)发送欢迎电邮。如果我设置 ACCOUNT_EMAIL_VERIFICATION =(强制性)
,则可以正常工作,用户将获得验证电子邮件。但是,由于我不需要任何电子邮件验证,所以用户应该注册并获得欢迎电子邮件。
How can I send a welcome email to a user who signs up on a django app(using django-allauth). If I set ACCOUNT_EMAIL_VERIFICATION = ("mandatory")
, it works fine, and the user gets a verification email. But since I dont require any email verification, so the user should simply signup and get a welcome email.
settings.py -
settings.py-
ACCOUNT_AUTHENTICATION_METHOD = ("email")
ACCOUNT_EMAIL_VERIFICATION = ("none")
ACCOUNT_SIGNUP_PASSWORD_VERIFICATION = False
ACCOUNT_UNIQUE_EMAIL = True
ACCOUNT_USERNAME_REQUIRED = False
EMAIL_CONFIRMATION_SIGNUP = True
ACCOUNT_EMAIL_REQUIRED =True
LOGIN_REDIRECT_URL = '/'
LOGOUT_URL = '/'
ACCOUNT_LOGOUT_ON_GET =False
ACCOUNT_LOGOUT_REDIRECT_URL = '/'
SOCIALACCOUNT_QUERY_EMAIL = (ACCOUNT_EMAIL_REQUIRED)
SOCIALACCOUNT_AUTO_SIGNUP = True
SOCIALACCOUNT_AVATAR_SUPPORT = ( 'avatar' in INSTALLED_APPS)
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = '##'
EMAIL_HOST_PASSWORD = '##'
EMAIL_PORT = 587
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
有没有我错过的设置发送欢迎注册邮件?还是要通过我的意见呢?似乎找不出来的方式。任何帮助都会很棒。谢谢。
Is there any setting I missed which sends the welcome signup mail? Or do I have to pass it through my views? Cant seem to figure out the way for this. Any help would be great. Thanks.
推荐答案
没有没有这样的设置,但你可以听一个信号,其中将有用户
和请求
在参数中。一旦收到发送电子邮件给用户。
No there is no such settings, but you can listen to a user_signed_up signal, which will have the user
and request
in parameters. Once it received send an email to the user.
将以下代码放在 models.py
文件中:来自allauth.account.signals的
Put the below code some where in models.py
file:
from allauth.account.signals import user_signed_up
from django.dispatch import receiver
@receiver(user_signed_up, dispatch_uid="some.unique.string.id.for.allauth.user_signed_up")
def user_signed_up_(request, user, **kwargs):
# user signed up now send email
# send email part - do your self
这篇关于Django-allauth:发送欢迎电子邮件(无验证)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!