hekevintran
hekevintran

Reputation: 23722

Why is my send_mail() command not working in Django?

I put the following in my settings.py file. The email address there is a test one. I found the email settings from Webfaction's site:

EMAIL_HOST = 'smtp.webfaction.com'
EMAIL_HOST_USER = 'hekevintran_test'
EMAIL_HOST_PASSWORD = 'testpass'
EMAIL_PORT = 465
EMAIL_USE_TLS = True

This is what my file looks like:

from django.core.mail import send_mail

send_mail(subject='subject',
          message='message',
          from_email='[email protected]',
          recipient_list=['[email protected]'],
          fail_silently=False)

When I run the above it stalls a long time and then gives me this error:

SMTPServerDisconnected: Connection unexpectedly closed

What am I doing wrong?

Upvotes: 5

Views: 5273

Answers (3)

Radren
Radren

Reputation: 305

I had this problem too. I deleted EMAIL_PORT and set EMAIL_USE_TLS = True. Now it is work.

Upvotes: 0

probos
probos

Reputation: 11

I had this problem with my hosted account at asmallorange.com. There, it was a firewall problem. I would suggest contacting support and ensuring port 465 can get through the firewall.

Upvotes: 1

Paolo Bergantino
Paolo Bergantino

Reputation: 488414

I have a Django project on Webfaction right now that is properly sending emails. The only difference between your settings and mine is that I did not specify EMAIL_PORT or EMAIL_USE_TLS. Try it out without those settings and let Django use the default it has and see if it works.

For reference's sake, the default settings are:

EMAIL_PORT = 25
EMAIL_USE_TLS = False

Upvotes: 11

Related Questions