-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemail_utils.py
32 lines (25 loc) · 915 Bytes
/
email_utils.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
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from credentials import gmail_credential
from credentials import email_list
import smtplib, datetime
def connectSmtp():
smtp = smtplib.SMTP_SSL('smtp.gmail.com', 465)
smtp.login(gmail_credential['GMAIL_ID'], gmail_credential['GMAIL_PASSWORD'])
return smtp
def makeMsg(tweets):
msg = MIMEMultipart()
today = datetime.datetime.now()
msg['Subject'] = f'Tweets. {today.strftime("%A %d. %B %Y")}'
content = ''
for tweet in tweets:
content += f'{tweet["text"]}\n * tweet url: {tweet["tweet_url"]}\n * url: {tweet["url"]}'
content += '\n\n\n'
text = MIMEText(content)
print(content)
msg.attach(text)
return msg
def sendEmail(smtp, msg):
for addr in email_list:
msg["To"] = addr
smtp.sendmail(gmail_credential['GMAIL_ID'], addr, msg.as_string())