Django-allauth: send welcome email on signup (without verification)

user_2000 picture user_2000 · Jun 5, 2013 · Viewed 10.6k times · Source

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.

Answer

Aamir Adnan picture Aamir Adnan · Jun 5, 2013

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