Traceback (most recent call last):
File "/Users/n0body/auto_exec/cpolar.py", line 57, in <module>
smtpObj = smtplib.SMTP('localhost')
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/smtplib.py", line 255, in __init__
(code, msg) = self.connect(host, port)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/smtplib.py", line 341, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/smtplib.py", line 312, in _get_socket
return socket.create_connection((host, port), timeout,
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/socket.py", line 843, in create_connection
raise err
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/socket.py", line 831, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 61] Connection refused
完整报错信息如上。
运行环境为Python 3.9, MacOS Monterey
笔者正在写一个自动化小工具,将爬虫每天爬取的信息打包成邮件的形式发送到指定邮箱,但是有时能发送成功,有时却不行。这种时有时无的Bug让人很烦恼。过了一天,一次都发送不成功了。为此我翻阅StackOverFlow,Github都找不到对应的解决,或者说不适用于我。
解决:
在查询完Google无果后,转而问询ChatGPT,发现是邮箱服务没开。。。。
使用
sudo postfix status
查询服务开启状态
使用
sudo postfix start
启动服务
启动完成之后,邮箱服务也能正常使用了