通过Zoho SMTP发送电子邮件 [英] Send email through Zoho SMTP

查看:1103
本文介绍了通过Zoho SMTP发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从我基于django的网站发送电子邮件,但是我有一些问题 - SMTPServerDisconnected连接意外关闭
我的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。任何人都可以解决这个问题?



感谢您的帮助

解决方案

我有连接超时的同样的问题。在我看来,默认Django SMTP库中的SSL套接字存在问题。在Django的开发版本中,有一个选项可以设置 EMAIL_USE_SSL = True ,允许使用隐式 TLS连接(而不是 explicit ,由 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)的访问Zoho的SMTP服务器smtplib (见下文脚本)。所以,如果你想要一个微不足道的修复,你可以去那条路线。我已经在Django 1.5.1中测试过,它的作用就像一个魅力。



这是独立的Python脚本(可以在Django项目中使用) ):

  import smtplib 
from email.mime.text import MIMEText

#定义从
sender ='sender@example.com'
recipient ='recipient@example.com'

#创建消息
msg = MIMEText(消息文本)
msg ['Subject'] =从python发送
msg ['From'] = sender
msg ['To'] =收件人

#使用SSL选项创建服务器对象
server = smtplib.SMTP_SSL('smtp.zoho.com',465)

#通过服务器执行操作
server.login(' mail@example.com','password')
server.sendmail(sender,[recipient],msg.as_string())
server.quit()

尝试检查上面的脚本是否与您的Zoho凭据一起运行,然后将其插入到您的Web项目中。祝你好运!


I am trying to send email from my django-based website, but I got some problem - SMTPServerDisconnected Connection unexpectedly closed My setting.py:

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.zoho.com'
EMAIL_PORT = 465
EMAIL_HOST_USER = 'me@mydomain.com'
EMAIL_HOST_PASSWORD = 'XXXXXX'

I am using django 1.5.1, python 2.7.3. Anyone can solve this problem?

Thanks for your help

解决方案

I'm having the same problem with connection timeouts. It seems to me that there are issues around SSL sockets in the default Django SMTP library. In the development version of Django there is an option to set EMAIL_USE_SSL = True which allows for the use of an implicit TLS connection (as opposed to explicit, which is specified by EMAIL_USE_TLS = True). Generally the former (implicit) uses port 465, while the latter (explicit) uses port 587. See the Django docs -- compare the development version with version 1.5. Note that the option EMAIL_USE_SSL is NOT present in 1.5.

Thus, the problem is that Zoho's default SMTP server uses port 465 and requires SSL, but the EMAIL_USE_TLS option doesn't fulfill this requirement. (Side note: maybe try setting this option to False? I didn't try that.) Anyway, my best guess is that this is a Django-specific issue and may not be solved until 1.7.

As for a solution to your problem: you can definitely access Zoho's SMTP server with Python (2.7.1)'s smtplib (see script below). So, if you want a slightly inelegant fix, you could go that route. I've tested this in Django 1.5.1 and it works like a charm.

Here's the stand-alone Python script (which can be adapted for use in a Django project):

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()

Try checking that the above script runs with your Zoho credentials before plugging it into your web project. Good luck!

这篇关于通过Zoho SMTP发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆