1

I'm trying to send email with django. Here's my settings.py file.

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'mymail@gmail.com'
EMAIL_HOST_PASSWORD = 'mailpassword'
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = 'mymail@gmail.com'

I've also enabled access to less secure apps in the gmail settings.

On the production server whenever I try to send an email, it's raising an error in the command line upstream prematurely closed connection while reading response header from upstream.

On webpage it's showing 502 Bad Gateway error.

How can we solve this issue? Thank You . . .

  • Post your code that actually sends the email please. – Selcuk May 07 '18 at 07:45
  • @Selcuk Sir, I'm sending an email to reset password & using the built in code of Django itself by simple adding it's related URLs. It's working perfectly fine in the development server, but on the production it's raising above errors! –  May 07 '18 at 07:48
  • I experienced a similar problem, and it turned out that the problem was related to the email address used as "From:" to log server errors in production (by default it is `root@localhost`and it's set by the SERVER_EMAIL setting). Ref: https://docs.djangoproject.com/en/2.0/ref/settings/#std:setting-SERVER_EMAIL – Paolo Stefan May 07 '18 at 07:49
  • @PaoloStefan Sir, I changed SERVER_EMAIL = 'mymail@gmail.com'. But, still facing the same problem :( –  May 07 '18 at 07:54
  • So, maybe this answer can help: https://stackoverflow.com/a/6367458/719247 – Paolo Stefan May 07 '18 at 08:05

0 Answers0