13

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.

karthikr
  • 97,368
  • 26
  • 197
  • 188
user_2000
  • 1,103
  • 3
  • 14
  • 26

2 Answers2

26

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
Aamir Rind
  • 38,793
  • 23
  • 126
  • 164
  • 1
    Thanks for the response! that worked!! To send the email I use send_mail('Welcome', 'Your registration at abc.com is successful. Your username is %s' %user.username, 'Hello ', [user.email]) Although I don't know how to use a template here(not a single line of text) for the body of the email and I'll figure it out, your solution did the trick! Thanks – user_2000 Jun 05 '13 at 17:03
  • what is the use of dispatch_uid? – Mohammad Kamrul Hasan Nov 06 '20 at 02:13
  • A unique identifier for a signal receiver in cases where duplicate signals may be sent. See [Preventing duplicate signals](https://docs.djangoproject.com/en/3.1/topics/signals/#preventing-duplicate-signals) for more information. – Aamir Rind Nov 06 '20 at 18:48
7

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.

pennersr
  • 6,306
  • 1
  • 30
  • 37
  • Thanks, I cant use "optional" as I don't want to send the confirmation email on signup (even if the user doesnt verify). Perhaps Im using user_signed_up signal, that made it work. – user_2000 Jun 05 '13 at 17:06
  • can you share your user_signed_up signal? – milan Apr 17 '16 at 14:47