-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
35 lines (27 loc) · 1 KB
/
main.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
import os
import random
import smtplib
from datetime import datetime as dt
import pandas as pd
from dotenv import load_dotenv
load_dotenv()
sender_email = os.getenv("SENDER_EMAIL")
password = os.getenv("PASSWORD_SENDER")
data_birthdays = pd.read_csv("birthdays.csv")
today = dt.now()
# or you can do data.iterrows() and use dict compresion to build a dict
todays_birthdays = data_birthdays[
(data_birthdays.month == today.month) & (data_birthdays.day == today.day)
]
with open(f"letter_templates/letter_{random.randint(1,3)}.txt") as file_letter:
letter_msg = file_letter.read()
for row in todays_birthdays.to_dict(orient="records"):
email_body = letter_msg.replace("[NAME]", row["name"])
with smtplib.SMTP("smtp.gmail.com") as connection:
connection.starttls()
connection.login(user=sender_email, password=password)
connection.sendmail(
from_addr=sender_email,
to_addrs=row["email"],
msg="Subject:Happy Birthday!\n\n" + email_body,
)