Abedy
Abedy

Reputation: 371

django-sendgrid-v5 Everything seems to work fine but mails don't get delivered

I'm using the django-sendgrid-v5 package to send mails in django. Everything works fine but the mail never reaches to the inbox, neither spam. Here are my current configurations:

.env file:

EMAIL_BACKEND='sendgrid_backend.SendgridBackend' 
SENDGRID_API_KEY='SG.the_rest_of_the_api_key'

settings.py file:

EMAIL_BACKEND = env('EMAIL_BACKEND')
SENDGRID_API_KEY = env('SENDGRID_API_KEY')
SENDGRID_SANDBOX_MODE_IN_DEBUG=False

and my mail function:

from django.core.mail import send_mail

send_mail( mail_subject, message, '[email protected]', [to_email], fail_silently=False )

On sending the email, I get no error, but still the mail doesn't get delivered. What could I be missing?

Upvotes: 3

Views: 1821

Answers (1)

Abedy
Abedy

Reputation: 371

I finally worked it through. The problem was Sender Authentication, Which By the way is not very elaborate in the documentation.

After generating an API key you're supposed to add some CNAME records to your DNS service provider for sendgrid to be authenticated to send emails.

With a lot of help from This medium article

So the problem was not on the code.

Upvotes: 2

Related Questions