Sendmail Errno[61] Connection Refused(Sendmail Errno[61] 连接被拒绝)
问题描述
我一直在尝试让我的应用程序将一些输出的文本邮寄到电子邮件中.为简化起见,我隔离了脚本:
I've been trying to get my application to mail some outputted text to an email. For simplification I have isolated the script :
import smtplib
import sys
import os
SERVER = "localhost"
FROM = os.getlogin()
TO = [raw_input("To : ")]
SUBJECT = "Message From " + os.getlogin()
print "Message : (End with ^D)"
TEXT = ''
while 1:
line = sys.stdin.readline()
if not line:
break
TEXT = TEXT + line
# Prepare actual message
message = """
From: %s
To: %s
Subject: %s
%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT)
# Send the mail
server = smtplib.SMTP(SERVER)
server.sendmail(FROM, TO, message)
server.quit()
此脚本输出:
Traceback (most recent call last):
File "/Users/christianlaustsen/Dropbox/Apps - Python/mail/smtplib_mail.py", line 32, in <module>
server = smtplib.SMTP(SERVER)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/smtplib.py", line 239, in __init__
(code, msg) = self.connect(host, port)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/smtplib.py", line 295, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/smtplib.py", line 273, in _get_socket
return socket.create_connection((port, host), timeout)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/socket.py", line 512, in create_connection
raise error, msg
error: [Errno 61] Connection refused
如您所见,连接被拒绝.我在 Mac OS X Snow Leopard 上运行 Python 2.6(如果相关).
So as you can see, the connection is being refused. I'm running Python 2.6 on Mac OS X Snow Leopard (if that's relevant).
我已经尝试了很多搜索,但一直无法找到解决方案.任何帮助将不胜感激.
I have tried searching around a lot, but haven't been able to find a solution. Any help will be appreciated.
推荐答案
我猜你的本地机器上没有安装任何 SMTP 服务器.
My guess is that you do not have any SMTP server installed on your local machine.
如果您的电子邮件不敏感,请打开一个 Gmail 帐户并使用它发送您的电子邮件使用 Python.
If your emails are not sensitive, open a Gmail account and send your emails using it with Python.
这篇关于Sendmail Errno[61] 连接被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Sendmail Errno[61] 连接被拒绝


基础教程推荐
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 筛选NumPy数组 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01