当我连接手机时,无法通过django的send_mail()
通过3g数据连接发送邮件。它需要一段时间,并且失败并显示Network is unreachable error
,
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/root/.virtualenvs/local_env/local/lib/python2.7/site-packages/django/core/mail/__init__.py", line 62, in send_mail
return mail.send()
File "/root/.virtualenvs/local_env/local/lib/python2.7/site-packages/django/core/mail/message.py", line 283, in send
return self.get_connection(fail_silently).send_messages([self])
File "/root/.virtualenvs/local_env/local/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 92, in send_messages
new_conn_created = self.open()
File "/root/.virtualenvs/local_env/local/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 50, in open
self.connection = connection_class(self.host, self.port, **connection_params)
File "/usr/lib/python2.7/smtplib.py", line 251, in __init__
(code, msg) = self.connect(host, port)
File "/usr/lib/python2.7/smtplib.py", line 311, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib/python2.7/smtplib.py", line 286, in _get_socket
return socket.create_connection((host, port), timeout)
File "/usr/lib/python2.7/socket.py", line 571, in create_connection
raise err
error: [Errno 101] Network is unreachable
另一方面,4g connection
上的邮件发送成功。
我对网络知之甚少,因此无法理解原因。
的修改
通过localhost执行此操作。
答案 0 :(得分:2)
由于您在进行本地开发时仅使用手机,因此可能无法实际发送电子邮件,只需将其打印到控制台即可。
为此,请将其放入您的设置中:
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
记录在案here。