我尝试使用不同的端口,并在互联网上找到解决方案,但我仍然无法修复它。我尝试将localhost更改为127.0.0.1,还尝试将端口号更改为所有类型的值,但仍然不起作用。如果能帮上大忙,我们将不胜感激。
import tkinter
import smtplib
import socket
from email.parser import Parser
smtp = smtplib.SMTP
user = ""
password = ""
def connect():
print(msg_entry.get())
smtp = smtplib.SMTP("localhost", 587)
#smtp.login(user,password)
smtp.sendmail(from_entry.get(), to_entry.get(), msg_entry.get())
smtp.quit()
app = tkinter.Tk()
app.title("test")
to_label = tkinter.Label(app,text="To:")
to_entry = tkinter.Entry(app)
from_label = tkinter.Label(app,text="From:")
from_entry = tkinter.Entry(app)
send_button = tkinter.Button(app,text="send",command=connect)
msg_label = tkinter.Label(app,text="Email:")
msg_entry = tkinter.Entry(app,width=50)
#pack(add) the widget to the app.
to_label.pack()
to_entry.pack()
from_label.pack()
from_entry.pack()
msg_label.pack()
msg_entry.pack()
send_button.pack()
#draw the window, have this at the end
app.mainloop()
每当我单击发送时,我都会收到错误消息:
Traceback (most recent call last):
File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python38\lib\tkinter\__init__.py", line 1883, in __call__
return self.func(*args)
File "C:/Users/ADMIN/PycharmProjects/CourseOutcome3/EmailTransmitter-DAMPAC.py", line 15, in connect
smtp = smtplib.SMTP("localhost", 587)
File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python38\lib\smtplib.py", line 253, in __init__
(code, msg) = self.connect(host, port)
File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python38\lib\smtplib.py", line 339, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python38\lib\smtplib.py", line 308, in _get_socket
return socket.create_connection((host, port), timeout,
File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python38\lib\socket.py", line 808, in create_connection
raise err
File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python38\lib\socket.py", line 796, in create_connection
sock.connect(sa)
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
https://stackoverflow.com/questions/66835844
复制相似问题