This repository was archived by the owner on Jun 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.py
61 lines (48 loc) · 1.43 KB
/
util.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
import os
import json
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
def get_contacts():
contacts = {}
try:
with open('contacts.json', 'r') as contacts_f:
contacts = json.load(contacts_f)
except FileNotFoundError as e:
raise e
except json.JSONDecodeError as e:
raise e
except Exception as e:
raise e
return contacts
# TODO get picture to send
def send_email(image, type):
# Email I made for this project
fromaddr = "[email protected]"
# My wit email.
toaddr = "[email protected]"
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = "test"
body = type
msg.attach(MIMEText(body, 'plain'))
# File location + name for adding a file
filename = image
attachment = open(os.getcwd() + os.sep + image, "rb")
part = MIMEBase('application', 'octet-stream')
part.set_payload((attachment).read())
encoders.encode_base64(part)
part.add_header('Content-Disposition',
"attachment; filename= %s" % filename)
msg.attach(part)
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
# Password for email
server.login(fromaddr, "eaistuff")
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
server.quit()
return True