问题
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-
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.
回答1:
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.
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
回答2:
allauth indeed only sends confirmation mails. But, it does differentiate between the first (signup) confirmation mail and following ones (e.g. when the user adds a second email address).
For this purpose allauth has a "email confirmation at signup"
template (account/email/email_confirmation_signup_message.txt
, account/email/email_confirmation_signup_subject.txt
).
When using the builtin templates this hybrid confirmation/signup/welcome mail is identical to the regular email confirmation template, but you can override it and put your welcome message in there. Furthermore, set ACCOUNT_EMAIL_VERIFICATION
to "optional"
.
If all of this does not fit your needs, then you can hookup to the user_signed_up
signal and send a plain welcome mail yourself.
来源:https://stackoverflow.com/questions/16928297/django-allauth-send-welcome-email-on-signup-without-verification