蟒蛇SMTP类型错误:sendmail的(),失踪1人需要的位置参数: '味精'
问题描述:
import tkinter
import smtplib
import socket
from email.parser import Parser
smtp = smtplib.SMTP
user = ""
password = ""
def connect():
print(msg_entry.get())
smtp("localhost",25)
#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()
每当我点击发送按钮,我得到这个错误蟒蛇SMTP类型错误:sendmail的(),失踪1人需要的位置参数: '味精'
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python34\lib\tkinter\__init__.py", line 1533, in __call__
return self.func(*args)
File "C:\Users\Joshua\Documents\Code\Python\Jmail\main.py", line 17, in connect
smtp.sendmail(from_entry.get(),to_entry.get(),msg_entry.get())
TypeError: sendmail() missing 1 required positional argument: 'msg'
答
试试这个:
smtp = smtplib.SMTP("localhost",25)
smtp.sendmail(from_entry.get(),to_entry.get(),msg_entry.get())
+0
非常感谢你,谢谢你的帮助和教我:) – get52 2015-02-23 17:00:39
是什么你的问题? – 2015-02-23 16:10:43