django send_mail not working now.

ive done this before but send_mail is not working now. i do have my credentials right and don’t know y its not working. i mean its going through the process and returning the page i want but im not getting emails.

settings.py

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAiL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = 'example@gmail.com'
EMAIL_HOST_PASSWORD = '**********'

views.py

subject = subj
message = "This is my message"
sender = settings.EMAIL_HOST_USER
to = ['example2@gmail.com',]

send_mail(subject, message, sender, to, fail_silently= True)

i also made sure that i am getting the form input right. The page is throwing no errors as well.

Note: i have enabled 2-step verification for the sender email and i have also setup an app password for the sender mail.
i have turned off fail_silently to debug and this is the error page i get:

I keep a test program handy to verify that emails are working. It’s run from the command line and it tries to send a short email.

I took the example from the Python docs for an SMTP Example, with hard-coding the variables instead of being prompted for them, and substituting the appropriate server variables.

Creating a script like that with using set_debuglevel(2) should provide enough detail to help you determine where things are going wrong.

Also see Django how to send_mail via local sendmail - #6 by KenWhitesell for another approach I’ve used.

1 Like

let me check it out. But the other app i used send mail is still working with no issues…!

The issue was a typo in my variable. Silly me…