GUI Version Of Email Sender

This is the gui version of my email sender
mail@pastecode.io avatar
unknown
python
2 months ago
1.8 kB
1
Indexable
Never
import smtplib
import tkinter as tk

root = tk.Tk()
root.geometry("400x200")
root.title("Email Sender")
root.config(bg="Green")

class Application(tk.Frame):
    
    def __init__(self, master = None):
        super().__init__(master)
        self.master = master
        self.pack()
        self.create_widgets()
        self.canv = tk.Canvas()


    def create_widgets(self):
        self.email = tk.Entry()
        self.email.pack(side="top", padx=10, pady=20)
        self.content = tk.Entry()
        self.content.pack(side="top",padx=10,pady=20)
        self.send = tk.Button(self, text="Send",command=self.sendMail, bg="red")
        self.send.pack(side="top",padx=10,pady=5)


        self.contentstr = tk.StringVar()
        self.emailstr = tk.StringVar()
        
        self.emailstr.set("Type a valid email here")
        self.contentstr.set("Type a message here to send")

        self.email["textvariable"] = self.emailstr
        self.content["textvariable"] = self.contentstr


        self.email.bind('<Key-Return>',
                            self.setemail)
        self.content.bind('<Key-Return>',
                            self.setcontent)

    
    def hi(self):
        print("hi")

    def setemail(self):
        to = self.emailstr.get()
    def setcontent(self):
        content = self.contentstr.get()

    def sendMail(self):
        global to, content

        server = smtplib.SMTP("smtp.gmail.com", 587)
        server.ehlo()
        server.starttls()
        my_email = "" #your email goes here
        server.login(my_email, "your password")
        server.sendmail(my_email, self.emailstr.get(), self.contentstr.get())
        server.close()
        print('Sent')

app = Application(root)

app.mainloop()
Leave a Comment