2009-12-23 84 views
2

發送電子郵件,我從連接超時的問題在Django

http://www.packtpub.com/article/friends-via-email-social-web-application-django-1.0

閱讀並遵循以下步驟: =>而改變我的 setting.py

SITE_HOST = '127.0.0.1:8000' 
DEFAULT_FROM_EMAIL = 'KSO Publisher <[email protected]>' 
EMAIL_HOST = 'smtp.xxxx.com.kh' 
EMAIL_PORT = '25' 
EMAIL_HOST_USER = '[email protected]' 
EMAIL_HOST_PASSWORD = 'mypassword' 
EMAIL_USE_TLS = False 

我去命令後line

[email protected]:~/workspace/kso$ python manage.py shell 
Python 2.5.2 (r252:60911, Jul 22 2009, 15:35:03) 
[GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)] on linux2 
Type "help", "copyright", "credits" or "license" for more information. 
(InteractiveConsole) 
>>> from django.core.mail import send_mail 
>>> emails = send_mail('Subject', 'Body of the message.','[email protected]',['[email protected]']) 

我得到了e恐怖消息。

Traceback (most recent call last): 
    File "<console>", line 1, in <module> 
    File "/var/lib/python-support/python2.5/django/core/mail.py", line 345, in send_mail 
    connection=connection).send() 
    File "/var/lib/python-support/python2.5/django/core/mail.py", line 271, in send 
    return self.get_connection(fail_silently).send_messages([self]) 
    File "/var/lib/python-support/python2.5/django/core/mail.py", line 166, in send_messages 
    new_conn_created = self.open() 
    File "/var/lib/python-support/python2.5/django/core/mail.py", line 131, in open 
    local_hostname=DNS_NAME.get_fqdn()) 
    File "/usr/lib/python2.5/smtplib.py", line 244, in __init__ 
    (code, msg) = self.connect(host, port) 
    File "/usr/lib/python2.5/smtplib.py", line 310, in connect 
    raise socket.error, msg 
error: (110, 'Connection timed out') 

有人知道究竟是什麼的問題;我怎麼能發送的郵件使用Django framworks

參考我已閱讀:

回答

7

'連接超時'表示Django無法連接到您的電子郵件服務器。 鍵入以下命令行:

telnet smtp.xxxx.com.kh 25 

你應該得到的電子郵件服務器的響應,是這樣的:

220 rufus Python SMTP proxy version 0.2 

如果沒有得到迴應,你已經找到了問題。

這裏有一個方便的命令在Linux上運行的本地開發服務器,:

sudo /usr/lib/python2.6/smtpd.py -n -c DebuggingServer 127.0.0.1:25 
+0

如果它是一個緩慢的220準備好響應,Django的SEND_EMAIL也將失敗與SMTP超時錯誤。郵件服務器在連接的客戶端上執行IDENT查詢,並且在完成之前不會提供220準備好的響應,這可能是緩慢的原因之一。還沒有找到解決辦法,如果您等待更長的時間來完成此操作,則最大超時標誌將會很不錯。 – radtek

1

你的代碼看起來是正確的,所以我認爲你的設置有問題。你是否正確地指定了EMAIL_HOSTEMAIL_PORT

注:它EMAIL_USE_TLSMAIL_USE_TLS,你可以設置你的地址None(3日在send_mail功能參數),如果你希望它把你的DEFAULT_FROM_EMAIL值。