Django Sending Email : SMTPServerDisconnected: Connection unexpectedly closed

后端 未结 6 1811

hello i want to sending email activation use django registration redux.

this is my setting.py

EMAIL_BACKEND = \'django.core.mail.backends.smtp.EmailBackend         


        
6条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-13 03:09

    Like myself, if your deployed django app is on heroku and using https meaning you need port 465, you should not forget to add these same values below here to your heroku Config Vars. It threw 'connection unexpectedly closed' error untill i had to add this.

    # settings.py

    EMAIL_HOST = 'smtp.sendgrid.net'
    EMAIL_HOST_USER = 'apikey'
    EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_HOST_PASSWORD')                   
                         # replace here with the long SendGrid API secret code 
                         # xyxyxyxyzzzyz on heroku's Config Vars
    EMAIL_PORT =  465 
    EMAIL_USE_SSL = True
    

    Without that, debugging on localhost or development sever will work (with port 587 under http) but not at deployment under port 465 with https

提交回复
热议问题