-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemailapp.py
85 lines (61 loc) · 2.66 KB
/
emailapp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from tkinter import *
from tkinter import ttk
import smtplib
import webbrowser
def sendemail():
try:
sender = account.get()
recipient = [receiver.get()]
sub = subject.get()
pswrd = password.get()
msg = msgbody.get('1.0','end')
msgtosend = """\
From: %s
To: %s
Subject: %s
%s
""" % (sender, recepient, sub, msg)
mail = smtplib.SMTP('smtp.gmail.com',587)
mail.starttls()
mail.login(sender, pswrd)
mail.sendmail(sender, recepient, msgtosend)
mail.close()
ttk.Label(mainframe, text="Email sent successfully").grid(column=4,row=9,sticky=W)
except Exception as e:
ttk.Label(mainframe, text=str(e)).grid(column=4,row=9,sticky=W)
def setup(event):
webbrowser.open_new(r"https://www.google.com/settings/security/lesssecureapps")
root = Tk()
root.title("Send an Email via Gmail !!")
mainframe = ttk.Frame(root, padding="3 3 12 12")
mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
mainframe.columnconfigure(0, weight=1)
mainframe.rowconfigure(0, weight=1)
account = StringVar()
password = StringVar()
receiver = StringVar()
subject = StringVar()
msgbody = StringVar()
a = Label(mainframe, text="To use this app turn this setting ON for your account", fg="blue", cursor="hand2")
a.grid(columnspan=2,column=3, row=0, sticky=W)
a.bind("<Button-1>", setup)
ttk.Label(mainframe, text="Your Email Account: ").grid(column=0, row=1, sticky=W)
account_entry = ttk.Entry(mainframe, width=30, textvariable=account)
account_entry.grid(column=4, row=1, sticky=(W, E))
ttk.Label(mainframe, text="Your Password: ").grid(column=0, row=2, sticky=W)
password_entry = ttk.Entry(mainframe, show="*", width=30, textvariable=password)
password_entry.grid(column=4, row=2, sticky=(W, E))
ttk.Label(mainframe, text="Recepient's Email Account: ").grid(column=0, row=3, sticky=W)
receiver_entry = ttk.Entry(mainframe, width=30, textvariable=receiver)
receiver_entry.grid(column=4, row=3, sticky=(W, E))
ttk.Label(mainframe, text="Let's Compose").grid(column=2, row=5, sticky=W)
ttk.Label(mainframe, text="Subject: ").grid(column=0, row=6, sticky=W)
subject_entry = ttk.Entry(mainframe, width=30, textvariable=subject)
subject_entry.grid(column=4, row=6, sticky=(W, E))
ttk.Label(mainframe, text="Message Body: ").grid(column=0, row=7, sticky=W)
msgbody = Text(mainframe, width=30, height=10)
msgbody.grid(column=4, row=7, sticky=(W, E))
ttk.Button(mainframe, text="Send Email", command=sendemail).grid(column=4,row=8,sticky=E)
for child in mainframe.winfo_children(): child.grid_configure(padx=5, pady=5)
account_entry.focus()
root.mainloop()