-
Notifications
You must be signed in to change notification settings - Fork 0
/
send.py
53 lines (39 loc) · 1.5 KB
/
send.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
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import notion
from dotenv import load_dotenv
import os
import random
load_dotenv()
email = os.getenv("EMAIL_FROM")
# print(email)
password = os.getenv("EMAIL_PW")
# print(password)
RANDOM_SIGNOFF = True
print()
with open("/home/theop/notion-email/recipients.txt", "r") as f:
recip = f.read().splitlines()
with open("/home/theop/notion-email/to.txt", "r") as f:
to = f.read().splitlines()
with open("/home/theop/notion-email/signoffs.txt", "r") as f:
signoffs = f.read().splitlines()
signoff = random.choice(signoffs) if RANDOM_SIGNOFF else "Welcome to the Renaissance"
s = smtplib.SMTP('smtp.gmail.com', 587)
s.starttls()
s.login(email, password)
call, date = notion.get_call()
# call_list = call.splitlines()
body = "Here is the rehearsal call for tomorrow!<br><br>" + '<font face="Courier New, Courier, monospace">' + call.replace("\n", "<br>") + "</font>"
link = MIMEText("<br><b>Week at a Glance: " + '<a href="https://theoparker.notion.site/6e08eaffba374dd9a1786c66ca3845fb?v=45a78417f24e4681851c7ed282836123&pvs=4">here</a></b>', 'html')
sign = "\n\n" + signoff + ",\nTheo"
message = MIMEMultipart()
message["Subject"] = "Something Rotten Rehearsal - " + date
message['To'] = ', '.join(to)
message["Cc"] = ', '.join(recip)
message["From"] = email
message.attach(MIMEText(body, "html"))
message.attach(link)
message.attach(MIMEText(sign, "plain"))
s.sendmail(email, recip, message.as_string())
s.quit()