Python smtplib,starttls 超时
我正在尝试为我在办公室网络上运行的小型监控脚本设置一些基本的电子邮件功能。在我的 Ubuntu 10.10 服务器上运行脚本(见下文)工作正常,但是当我在 Windows 桌面计算机上运行它时,它会在 send: 'STARTTLS\r\n'
with reply 上超时: '451 4.7.0 等待客户端输入超时\r\n'
。
虽然我无论如何都会在 Linux 服务器上运行它,但我很好奇为什么它不能在 Windows 下运行。是Python版本不同导致的问题吗?
设置:
SMTP 服务器:Exchange 2010、Windows Server 2008 R2 x64
Python 计算机 #1:Windows 7 SP1 x64、Python 2.7.1 ---(失败)
Python 计算机 #2:Ubuntu 服务器 10.10 x86、 Python 2.6.6 ---(有效)
脚本:
# -*- coding: utf-8 -*-
import smtplib
def main():
SERVER="exchange-serv"
FROM = "[email protected]"
TO = ["[email protected]"]
TEXT = '''\
From: [email protected]
Subject: testin'
Test message
'''
server = smtplib.SMTP(SERVER)
server.set_debuglevel(1)
server.starttls()
server.login('user', 'pass')
server.sendmail(FROM, TO, TEXT)
server.quit()
if __name__ == "__main__":
main()
I'm trying to set up some basic email functionality for a small monitoring script I'm running on our office network. Running the script (see below) on my Ubuntu 10.10 server works fine, but when I run it on my Windows desktop machine it times out on send: 'STARTTLS\r\n'
with reply: '451 4.7.0 Timeout waiting for client input\r\n'
.
While I will be running this on the Linux server anyway, I'm curious as to why it's not working under Windows. Is it the differing Python versions that are causing the problem?
Setup:
SMTP server: Exchange 2010, Windows Server 2008 R2 x64
Python machine #1: Windows 7 SP1 x64, Python 2.7.1 --- (fails)
Python machine #2: Ubuntu server 10.10 x86, Python 2.6.6 --- (works)
Script:
# -*- coding: utf-8 -*-
import smtplib
def main():
SERVER="exchange-serv"
FROM = "[email protected]"
TO = ["[email protected]"]
TEXT = '''\
From: [email protected]
Subject: testin'
Test message
'''
server = smtplib.SMTP(SERVER)
server.set_debuglevel(1)
server.starttls()
server.login('user', 'pass')
server.sendmail(FROM, TO, TEXT)
server.quit()
if __name__ == "__main__":
main()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先想到的是 Windows 防火墙正在阻止来自 Python.exe 可执行文件的出站套接字连接。您是否尝试过使用 Python 建立任何其他类型的连接,例如使用 urllib2?如果是这样,结果如何?
假设您无法使用 Python 进行连接,请确保将 Python.exe 作为例外添加到 Windows 防火墙中。
The first thing that comes to mind is that the Windows Firewall is blocking outbound socket connections from the Python.exe executable. Have you tried using Python to establish any other types of connections, such as using
urllib2
? If so, what are the results?Assuming you cannot connect out using Python, then make sure to add Python.exe as an exception into Windows Firewall.