我试图在Mac上运行一个测试python服务器。
我在venv中使用了下面的脚本,但是什么也没有发生。我需要打ctrl C才能把提示带回来。
python -m smtpd -n -c DebuggingServer localhost:1025我尝试过其他几个端口8025和25,在25上我得到了一个错误的socket.error: [Errno 13] Permission denied
知道我可能做错了什么吗?
谢谢
-更新
Traceback (most recent call last):
File "scratchmail.py", line 10, in <module>
server = smtplib.SMTP('127.0.0.1:2525')
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/smtplib.py", line 253, in __init__
(code, msg) = self.connect(host, port)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/smtplib.py", line 339, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/smtplib.py", line 308, in _get_socket
return socket.create_connection((host, port), timeout,
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/socket.py", line 808, in create_connection
raise err
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/socket.py", line 796, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 61] Connection refused发布于 2020-05-22 00:09:18
当服务器启动时,您将看不到屏幕上的任何内容,但是尝试发送电子邮件,您应该看到控制台上的消息如下:
python -m smtpd -n -c DebuggingServer localhost:2525 ---------- MESSAGE FOLLOWS ----------
Content-Type: multipart/mixed; boundary="===============5184031310585311106=="
MIME-Version: 1.0
From: emg1@test.com
To: emmg2@test.com
Subject: SUBJECT OF THE MAIL
X-Peer: 127.0.0.1
--===============5184031310585311106==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
<body>
YOUR MESSAGE HERE
</body>
--===============5184031310585311106==--
------------ END MESSAGE ------------我编写了一个脚本来向刚启动的服务器发送电子邮件,如下所示:
#!/usr/bin/python
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from_addr = 'sender@mail.com'
to_addr = 'target@mail.com'
msg = MIMEMultipart()
msg['Subject'] = 'smtp test'
msg.attach(MIMEText("email body", 'plain'))
server = smtplib.SMTP('127.0.0.1:2525')
text = msg.as_string()
server.sendmail(from_addr, to_addr, text)
server.quit()发布于 2020-05-24 13:06:57
好的,如果我在venv之外启动服务器,我就可以让它正常工作。我不知道为什么,但我现在解决了问题。
https://stackoverflow.com/questions/61942258
复制相似问题