Log in

Email sending with smtp not working

  • 1
  • 31 May

The email settings in prod.py is correct. But the emails are not sent and worker gets timed out while using gunicorn.


DEFAULT_FROM_EMAIL = 'postmaster@sandbox60a52592d19044ae8dea65ffab8d069b.mailgun.org'
SERVER_EMAIL = DEFAULT_FROM_EMAIL
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.mailgun.org'

EMAIL_PORT = 587
EMAIL_HOST_USER = 'postmaster@sandbox60a52592d19044ae8dea65ffab8d069b.mailgun.org'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_USE_TLS = True


nitelyEsteban Castro Borsani
  • 2
  • 31 May

No idea. Try setting EMAIL_TIMEOUT = 3 (won't fix it, but it will log the error faster). You could run gunicorn from the CLI (not as a deamon), so you can check the error there. Or add the file handler to your settings and check the django.log

LOGGING = {
    # Removed for brevity
    # ...
    # Check the example.settings.py for the full config
    # ...
    'loggers': {
        '': {
            'handlers': ['console', 'mail_admins', 'file'],
            'level': 'ERROR',
            'propagate': False,
        },
        'django': {
            'handlers': ['console', 'mail_admins', 'file'],
            'level': 'ERROR',
            'propagate': False,
        },
    }
}
  • 1 Jun

I am running Gunicorn as CLI and not daemon. The mail isn't being sent even on development settings without gunicorn.It just infinitely loads without sending email.
I will try to get error using the methods.

nitelyEsteban Castro Borsani
  • 1 Jun

Try adding the time-out. My guess is it'll throw a connection timeout error. You should check the SMTP port is not being block. Run this command:

$ telnet smtp.mailgun.org 587

If you get timeout (or just hangs and does not connect) try port 2525 and port 25

  • 21 Jun

Hey thanks. I figured it out the other day. My VPS provider was blocking smtp requests.

This comment was deleted.
nitelyEsteban Castro Borsani
  • 3 Aug

There is a testing ground. Use it.

Reply