我正在尝试制作一个非常简单的电子邮件客户端。这将使我能够从学校向家里电脑发送电子邮件,因为学校已经阻止了outlook和gmail。当我尝试运行它时,它会显示:TypeError:get()缺少1个必需的位置参数:“index1” 我已经用星号替换了我的电子邮件和密码,以确保安全性。提前感谢:)
这是我的代码:
from tkinter import *
import tkinter as tk
from email.message import EmailMessage
import smtplib
window=Tk()
window.title('Email Client')
window.geometry('200x275')
textbox2=Text(window,width=20,height=10,bg='light grey')
label2=Label(window,text='Message')
textbox1=Text(window,width=20,height=1,bg='light grey')
label1=Label(window,text='Subject')
def email_alert(subject, body, to):
msg = EmailMessage()
msg.set_content(body)
msg['subject'] = subject
msg['to'] = to
user = "*******************"
msg['from'] = user
password = "*************"
server = smtplib.SMTP("smtp.gmail.com", 587)
server.starttls()
server.login(user, password)
server.send_message(msg)
server.quit()
if __name__ == '__main__':
def Send():
dialog = textbox1.get()
subject = textbox2.get()
email_alert(subject, dialog, "******************")
label1.pack()
textbox1.pack()
label2.pack()
textbox2.pack()
button1=Button(window,text='Send Email',width=10,height=1, command=Send)
button1.pack()
window.mainloop()