简体   繁体   中英

Why i cannot use gmail smtp in django?

This is my setting:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'prahbari82@gmail.com'
EMAIL_HOST_PASSWORD = 'My gmail password'
EMAIL_PORT = 587
EMAIL_USE_TLS = True

and i use CBV's:

from django.contrib.auth import views as auth_views
from django.urls import reverse_lazy


class UserLogin(auth_views.LoginView):
    template_name = 'accounts/login.html'


class UserPassReset(auth_views.PasswordResetView):
    template_name = 'accounts/password_reset_form.html'
    success_url = reverse_lazy('accounts:password_reset_done')
    email_template_name = 'accounts/password_reset_email.html'


class PasswordResetDone(auth_views.PasswordResetDoneView):
    template_name = 'accounts/reset_done.html'


class PasswordResetConfirm(auth_views.PasswordResetConfirmView):
    template_name = 'accounts/password_reset_confirm.html'
    success_url = reverse_lazy('accounts:password_reset_complete')


class PasswordResetComplete(auth_views.PasswordResetCompleteView):
    template_name = 'accounts/password_reset_complete.html'

But I don't get any errors I also turned on the less secure app! I also used 2 verification but it does not work!

TLS = True only if you are using port 465.

I encountered this challenge. I searched everywhere online but no answer. Finally, I got a hint which led me to try what worked for me.

1st: in your settings.py if you set EMAIL_USE_TLS = False ,

then set EMAIL_USE_SSL = True and EMAIL_PORT = 465 .

Otherwise, if you set EMAIL_USE_TLS = True ,

then set EMAIL_USE_SSL = False and EMAIL_PORT = 587 .

2nd: in Your terminal run; npm run build , instead of npm start .

NOTE: Always run npm run build whenever you make any changes in your front-end. Although, there is another way to make it automatic but that is not within the scope of this issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM