我从
读到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 <soeng@xxxx.com.kh>'
EMAIL_HOST = 'smtp.xxxx.com.kh'
EMAIL_PORT = '25'
EMAIL_HOST_USER = 'myusernamea@xxxx.com.kh'
EMAIL_HOST_PASSWORD = 'mypassword'
EMAIL_USE_TLS = False
进入命令行后
python@python-desktop:~/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.','soeng@xxxx.com.kh',['pythonkhmer@gmail.com'])
我收到了错误消息。
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发送邮件
参考资料我读过:
答案 0 :(得分:10)
'连接超时'表示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
答案 1 :(得分:1)
您的代码看起来正确,所以我认为您的设置存在问题。您是否肯定地指定了EMAIL_HOST
和EMAIL_PORT
?
注意:它的EMAIL_USE_TLS
不是MAIL_USE_TLS
,您可以将您的发件人地址(send_mail函数中的第3个参数)设置为None
,如果您希望它获取DEFAULT_FROM_EMAIL
值