import pandas, random, smtplib, datetime, os
connection = smtplib.SMTP('smtp.gmail.com', 587) connection.starttls() connection.login(user=USER_NAME, password=PASSWORD) files = os.listdir('letter_templates')
today = datetime.datetime.now() data = pandas.read_csv('birthdays.csv')
for row in range(0, len(data)): if data.iloc[row]['month'] == today.month and data.iloc[row]['day']: with open(f'/home/kumaran101088/birthday_wish/letter_templates/{random.choice(files)}') as body_file: content = body_file.read().replace('[NAME]', data.iloc[row]['name']).replace('Kumaran', 'Angela') connection.sendmail(from_addr=USER_NAME, to_addrs=data.iloc[row]['email'], msg=f'Subject: Happy Birthday!\n\n{content}')
connection.close()