我的setting.py文件:
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.zoho.com'
EMAIL_PORT = 465
EMAIL_HOST_USER = 'me@mydomain.com'
EMAIL_HOST_PASSWORD = 'XXXXXX'
我正在使用django 1.5.1和python 2.7.3,有人可以解决这个问题吗?
谢谢你的帮助
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.zoho.com'
EMAIL_PORT = 465
EMAIL_HOST_USER = 'me@mydomain.com'
EMAIL_HOST_PASSWORD = 'XXXXXX'
我正在使用django 1.5.1和python 2.7.3,有人可以解决这个问题吗?
谢谢你的帮助
我也遇到了连接超时的问题。在默认的Django SMTP库中,SSL套接字存在问题。在Django开发版本中有一个选项可以设置EMAIL_USE_SSL = True
,允许使用隐式 TLS连接(而不是由EMAIL_USE_TLS = True
指定的显式连接)。通常情况下,前者(隐式)使用端口465,而后者(显式)使用端口587。请参阅Django文档,比较开发版本和1.5版本。请注意,选项EMAIL_USE_SSL
在1.5版本中不存在。
因此,问题在于Zoho的默认SMTP服务器使用端口465并需要SSL,但EMAIL_USE_TLS
选项无法满足此要求。(副作用:也许尝试将此选项设置为False
?我没有尝试过。)总之,我的猜测是这是一个特定于Django的问题,并且可能要等到1.7版本才能解决。
至于解决您的问题的方案:您绝对可以使用Python(2.7.1)的smtplib
访问Zoho的SMTP服务器(请参见下面的脚本)。因此,如果您想要一个稍微不太优雅的解决方法,可以采用这种方式。我已在Django 1.5.1中测试过,它非常有效。
以下是独立的Python脚本(可适应于Django项目):
import smtplib
from email.mime.text import MIMEText
# Define to/from
sender = 'sender@example.com'
recipient = 'recipient@example.com'
# Create message
msg = MIMEText("Message text")
msg['Subject'] = "Sent from python"
msg['From'] = sender
msg['To'] = recipient
# Create server object with SSL option
server = smtplib.SMTP_SSL('smtp.zoho.com', 465)
# Perform operations via server
server.login('sender@example.com', 'password')
server.sendmail(sender, [recipient], msg.as_string())
server.quit()
在将上述脚本嵌入您的网络项目之前,请确保使用您的Zoho凭据运行它。祝您好运!
SMTPServerDisconnected: Connection unexpectedly closed
使用这些设置:
EMAIL_PORT = 465
EMAIL_BACKEND = 'django_smtp_ssl.SSLEmailBackend'
EMAIL_USE_SSL = True
EMAIL_HOST = 'smtp.zoho.com'
EMAIL_HOST_USER = 'dio@streetbarz.com'
EMAIL_HOST_PASSWORD = 'password'
在设置server.set_debuglevel(1)后,我发现我的DEFAULT_FROM_EMAIL与EMAIL_HOST_USER不同
DEFAULT_FROM_EMAIL = "dio@streetbarz.com"
加上那个修正后问题就解决了。
settings.py
中需要的代码,以使错误报告通过电子邮件工作:DEBUG = False
TEMPLATE_DEBUG = DEBUG
ADMINS = (('Yourname', 'youremail@yourdomain.com'),)
SERVER_EMAIL = constants.SENDER_EMAIL
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.zoho.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = constants.SENDER_EMAIL
EMAIL_HOST_PASSWORD = constants.EMAIL_PASSWORD
from django.core import mail
mail.send_mail(subject='Hello',
message='Body goes here',
from_email='user@example.com',
recipient_list=['user@example.com'])
转换为:
from django.core.mail import EmailMessage
email = EmailMessage(
subject='Hello',
body='Body goes here',
from_email='user@example.com',
to=['user@example.com'],
reply_to=['user@example.com'],
headers={'Content-Type': 'text/plain'},
)
email.send()
EMAIL_HOST = 'smtp.zoho.com'
EMAIL_HOST_USER = 'user@example.com'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_USE_SSL = False
pip install django-smtp-ssl
EMAIL_BACKEND = 'django_smtp_ssl.SSLEmailBackend'
EMAIL_HOST = 'mail.example.com'
EMAIL_PORT = 465
Zoho Mail的SMTP配置设置 - 使用TLS端口587,使用ssl 465。因此,如果您使用EMAIL_USE_TLS = True,则使用EMAIL_PORT = 587
。
与问题略有关联,但请注意Zoho Mail的免费计划不再提供IMAP/POP支持。希望这篇文章能够为您节省一些调试时间。
```
FREE PLAN
Up to 25 Users
5GB* /User, 25MB Attachment Limit
Webmail access only+. Single domain hosting.
```
< p >< em >+IMAP/POP支持仅在付费计划中提供。
https://www.zoho.com/workplace/pricing.html?src=zmail
旧的免费计划(2018年之前注册的?)似乎仍然支持IMAP/POP
来源:https://help.zoho.com/portal/community/topic/zoho-free-tier-pop-imap-activesync-no-longer-free
你的SMTP邮件后端类可能过时了。请前往
python/site-packages/django/core/mail/stmp.py
请检查文件并确保将USE_SSL作为选项。如果没有,请用一个包含该选项的文件替换整个文件。这是文件。我在ZOHO上使用它成功了。
对不起,我的回答格式不太好,这是我在SO上的第一次贡献...
尝试使用1而不是True:
EMAIL_USE_TLS = 1
EMAIL_PORT = 465
EMAIL_HOST = 'smtp.zoho.com'
EMAIL_HOST_USER = 'me@mydomain.com'
EMAIL_HOST_PASSWORD = 'XXXXXX'
或者尝试使用另一个端口:
EMAIL_USE_TLS = 1
EMAIL_PORT = 587
EMAIL_HOST = 'smtp.zoho.com'
EMAIL_HOST_USER = 'me@mydomain.com'
EMAIL_HOST_PASSWORD = 'XXXXXX'
msg['To'] = 'u1@ex.com;u2@ex.com'
和server.sendmail(sender, ['u1@ex.com', 'u2@ex.com'], msg.as_string())
。 - Rushi Agrawal