13

How do you send email from Django using a hosted SMTP account (specially on Namecheap)?

I thought this would be straight forward, and simply a matter of filling out the standard EMAIL_* fields in my settings.py.

However, after entering my credentials in both my settings.py and Thunderbird, Thunderbird can download and send email, but Django times out with the error "SMTPServerDisconnected: Connection unexpectedly closed" when attempting to do the same.

My working settings in Thunderbird for my outgoing server (SMTP):

Server Name: oxmail.registrar-servers.com
Port: 465
User Name: myuser@mydomain.com
Authentication method: Normal password
Connection Security: SSL/TLS

My non-working settings in my Django settings.py:

EMAIL_HOST = 'oxmail.registrar-servers.com'
EMAIL_HOST_USER = 'myuser@mydomain.com'
EMAIL_HOST_PASSWORD = 'mypassword'
EMAIL_PORT = 465
EMAIL_USE_TLS = True
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER

Aren't these settings identical? What am I doing wrong? Why does one work while the other fails?

Cerin
  • 60,957
  • 96
  • 316
  • 522

2 Answers2

27

Turns out the problem was that the default SMTP backend in Django does not support SSL, and my SMTP host required it (not just TLS). Fortunately, I found a dirt-simple SSL backend, added EMAIL_BACKEND = 'django_smtp_ssl.SSLEmailBackend' to my settings.py and everything just worked.

Cerin
  • 60,957
  • 96
  • 316
  • 522
  • 2
    Can I give you more reputation points somehow ? This just saved my sanity trying to connect to namecheap's SMTP server. – bchhun Jul 10 '14 at 07:39
  • over a year later it still works - I've just used it with Django 1.6.5 – Jonatas CD Oct 13 '14 at 03:27
  • It is now EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' You may edit the answer. http://stackoverflow.com/a/28075147/969984 – nizam.sp Jul 18 '15 at 19:03
8

The settings below:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'mail.yourdomain.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'no-reply@yourdomain.com'
EMAIL_HOST_PASSWORD = 'password'
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER

worked for me. My django version I tested with is 1.8.8.

Javed
  • 5,904
  • 4
  • 46
  • 71