skip to Main Content

I am learning Django Q and to see how it works I am trying to send email. But when i am checking my gmail, email is not received( I also checked spam). It is also not showing an error.
Following is the code:

Settings.py

EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_USE_SSL = False
EMAIL_HOST_USER = '***@gmail.com'
EMAIL_HOST_PASSWORD = '***'
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

Q_CLUSTER = {
'name': 'appName',
'retry': 5,
'workers': 4,
'orm': 'default',
'workers': 8,
'recycle': 500,
'timeout': 60,
'compress': True,
'save_limit': 250,
'queue_limit': 500,
'cpu_affinity': 1,
'label': 'Django Q',
'redis': {
    'host': '127.0.0.1',
    'port': 6379,
    'db': 0, }

}

View.py
Following is the function which I am calling when user successfully logs in

def welcome_mail(user):
    msg = 'Welcome to our website'
    # send this message right away
    async_task('django.core.mail.send_mail',
            'Welcome',
            msg,
            '[email protected]',
            [user.email],
            fail_silently=False,
            )
    print("Email Sent--------")        
    # and this follow up email in one hour
    msg = 'Here are some tips to get you started...'
    schedule('django.core.mail.send_mail',
             'Follow up',
             msg,
             '[email protected]',
             [user.email],
             schedule_type=Schedule.ONCE,
             next_run=timezone.now() + timedelta(hours=1))

2

Answers


  1. Your backend is a EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend', so it only prints the email on the console. This is usually used for testing purposes, such that no email is send to a (sample) user, but that you can see in the console how the email was supposed to look.

    You can work with an SMTP backend [Django-doc] with:

    EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
    Login or Signup to reply.
  2. To send emails from Django, using Google based account, you have to Allow less secure apps on Google Admin here – https://admin.google.com/ac/security/lsa

    Best of Luck

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search