1

Possible Duplicate:
Django - [Errno 111] Connection refused

I have found a a link on how to send email with django : https://docs.djangoproject.com/en/dev/topics/email/ i followed the example and i got this:

>>> from django.core.mail import send_mail
>>> send_mail('dfdf', 'dfdfdf', 'logadrinab@agile.com.ph', ['ddcahanap@agile.com.ph'])
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/django/core/mail/__init__.py", line 61, in send_mail
    connection=connection).send()
  File "/usr/local/lib/python2.7/dist-packages/django/core/mail/message.py", line 251, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/usr/local/lib/python2.7/dist-packages/django/core/mail/backends/smtp.py", line 79, in send_messages
    new_conn_created = self.open()
  File "/usr/local/lib/python2.7/dist-packages/django/core/mail/backends/smtp.py", line 42, in open
    local_hostname=DNS_NAME.get_fqdn())
  File "/usr/lib/python2.7/smtplib.py", line 239, in __init__
    (code, msg) = self.connect(host, port)
  File "/usr/lib/python2.7/smtplib.py", line 295, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "/usr/lib/python2.7/smtplib.py", line 273, in _get_socket
    return socket.create_connection((port, host), timeout)
  File "/usr/lib/python2.7/socket.py", line 571, in create_connection
    raise err
error: [Errno 111] Connection refused
>>> 

i think it's because of EMAIL_HOST and EMAIL_PORT, if it is so where can I find it and how to use it? If it is not can anyone give me an idea on how to send email in django?

thanks in advance...

Community
  • 1
  • 1
gadss
  • 21,687
  • 41
  • 104
  • 154

4 Answers4

3

In your settings.py for your project, make sure you set your EMAIL_HOST, EMAIL_PORT and other settings (like a username or password if your host requires authentication).

Also, make sure you are running the console using the manage.py shell command, and not your normal python shell, so django loads the settings correctly.

Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284
0

You are right, you need to specify correct host and port in settings.py. What server you are going to use? If it is your hosting provider's server, for example, it is better to contact hosting support to get this info.

dbf
  • 6,399
  • 2
  • 38
  • 65
0

You are getting an error because you have no mail transfer agent installed on you system.

You just need to install postfix package in default configuration (it will ask you some questions during install, just choose defaults).

And there is no need to altering your configuration or settings.py or whatever.

lig
  • 3,567
  • 1
  • 24
  • 36
0

You'll need to correctly configure the SMTP email backend for your current host and test it interactively like you just did.

It's possible that they're using TLS or an alternate port--you should look it up in your account settings. Alternatively you can configure Django to use a remote service host, like Gmail, to get yourself started if you have no other options.

Filip Dupanović
  • 32,650
  • 13
  • 84
  • 114