-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlogEmail.py
57 lines (47 loc) · 1.69 KB
/
logEmail.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
import smtplib
from email.message import EmailMessage
from tkinter import *
from backend import *
def run():
root = Tk()
root.title("Springfield Senior Home")
root.eval("tk::PlaceWindow . center")
root.configure(bg="#fae5ac")
e = Entry(root, width=50, highlightthickness=1)
e.configure(bg="white", fg="black")
e.pack()
def click():
email = e.get()
myLabel = Label(root, text="email sent")
myLabel.pack()
# Email stuff
date = date_today()
msg = EmailMessage()
msg["Subject"] = "Log delivery for " + date
msg["From"] = "[email protected]"
# Subject to Change
msg["To"] = email
# msg.set_content("Test email")
with open("visitor-logs/" + date + ".csv", "rb") as f:
file_data = f.read()
print("File data in binary", file_data)
file_name = f.name
print("File name is", file_name)
# line below is the problem, you need more perameters thats all dw
msg.add_attachment(
file_data, maintype="application", subtype="csv", filename=file_name
)
server = smtplib.SMTP("smtp.gmail.com", 587)
server.starttls()
with open("password.txt", "r") as f:
server.login("[email protected]", f.read().strip())
print("Login succeeded")
server.send_message(msg)
print("email sent")
server.quit()
myButton = Button(root, text="Send", command=click)
myButton.configure(bg="#fae5ac", highlightbackground="#fae5ac", fg="black")
myButton.pack()
root.mainloop()
if __name__ == "__main__":
run()