I'm unable to send email via smtp using celery task and DRF.
I have the following constants in settings.py
# Celery settings
CELERY_BROKER_URL = 'redis://127.0.0.1:6379/0'
CELERY_RESULT_BACKEND = 'redis://127.0.0.1:6379/0'
# Email settings
EMAIL_BACKEND ='django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = MY_EMAIL
EMAIL_HOST_PASSWORD = MY_PASSWORD
EMAIL_USE_TLS = True
EMAIL_USE_SSL = False
tasks.py
from django.core.mail import send_mail
from celery import shared_task
@shared_task
def send_verification_email(user_email):
send_mail(
subject="test email",
message="testing",
from_email=settings.EMAIL_HOST_USER,
recipient_list=[user_email],
fail_silently=False
)
views.py
class RegisterUserAPIView(generics.GenericAPIView):
...
user_email = ...
send_verification_email.delay(user_email = user_email)
...
The error I'm getting is
raised unexpected: SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:992)')
Also, if i'm using console instead of smtp in below EMAIL_BACKEND, i'm able to send emails to the console without any problem..
EMAIL_BACKEND ='django.core.mail.backends.console.EmailBackend'
Not understanding how to fix this issue.