0
電子メールを送信するプログラムを作成しようとしています。しかし、私はそれをしようとした場合、私はTkinter smtplibエラーが定義されていません
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Pivo\AppData\Local\Programs\Python\Python35-32\lib\tkinter\__init__.py", line 1550, in __call__
return self.func(*args)
File "C:\Users\Pivo\Desktop\emailtkinter.py", line 24, in th
server.sendmail(vari2.get(), toaddrs12, message)
NameError: name 'server' is not defined
エラーを取得する完全なコード:
import smtplib
from tkinter import *
root = Tk()
class FullScreenApp(object):
def __init__(self, master, **kwargs):
self.master=master
pad=3
self._geom='200x200+0+0'
master.geometry("{0}x{1}+0+0".format(
master.winfo_screenwidth()-pad, master.winfo_screenheight()-pad))
master.bind('<Escape>',self.toggle_geom)
def toggle_geom(self,event):
geom=self.master.winfo_geometry()
print(geom,self._geom)
self.master.geometry(self._geom)
self._geom=geom
app=FullScreenApp(root)
def fn():
def th():
a = text.get("1.0", END)
dgc = assa.get()
message = dgc, a
server.sendmail(vari2.get(), toaddrs12, message)
server.quit
Label(root, text='To').pack()
toaddrs12 = StringVar()
toaddrs1 = Entry(root, textvariable=toaddrs12).pack()
Label(root, text='Subject').pack()
assa = StringVar()
ass = Entry(root, textvariable=assa).pack()
Label(root, text='Body').pack()
text = Text(root)
text.pack()
btn = Button(root, text='Send', command=th)
btn.pack()
b = Label(root, text='SMTP Server')
vari1 = StringVar()
ab = Entry(root, textvariable=vari1)
b.pack()
ab.pack()
ba = Label(root, text = 'Email')
ba.pack()
vari2 = StringVar()
c = Entry(root, textvariable=vari2)
c.pack()
ca = Label(root, text = 'Password')
ca.pack()
vari3 = StringVar()
widget = Entry(root, show="*", textvariable=vari3)
widget.pack()
def connect():
print(vari1.get())
print(vari2.get())
print(vari3.get())
server = smtplib.SMTP(vari1.get(), 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login(vari2.get(), vari3.get())
b.pack_forget()
ab.pack_forget()
ba.pack_forget()
c.pack_forget()
ca.pack_forget()
widget.pack_forget()
btn1.pack_forget()
fn()
btn1 = Button(root, command = connect, text = 'Connect')
btn1.pack()
root.mainloop()
おかげでこの日を! –