Birthday Email Automate Sender

Birthday Email Automate Sender

This app will help you not to forget your loved ones’ birthdays and send them emails when it is their birthday.

Installation:

  1. You must have an email account without google security and enter your email and password in the code.
  2. Create a file called birthdays.csv and insert info like this : name,email,year,month,day example: Test_Name,[email protected],1999,03,10
  3. Download the letter_1, letter_2, letter_3 and put them in a folder called letter_templates
  4. Edit the letter_1 – 3 and change the msg

Code:

import datetime as dt
import pandas
import random
import smtplib

# Email and password.

my_email = "GMAIL EMAIL"
password = "PASSWORD"

# Date format.
now = dt.datetime.now()
month = now.month
day = now.day
today = (month, day)

# Read the birthday files.
data = pandas.read_csv("birthdays.csv")
new_dict = {(data_row.month, data_row.day): data_row for (index, data_row) in data.iterrows()}

# Check if the Today day and month are in the list.
if (month, day) in new_dict:
    birthday_person = new_dict[today]
    with open(f"letter_templates/letter_{random.randint(1, 3)}.txt") as file_data:
        new_data = file_data.read()
        new_data = new_data.replace("[NAME]", birthday_person["name"])

    with smtplib.SMTP("smtp.gmail.com") as connection:
        connection.starttls()
        connection.login(user=my_email, password=password)
        connection.sendmail(from_addr=my_email, to_addrs=birthday_person["email"],
                            msg=f"Subject:Happy Birthday!\n\n{new_data}")

        print(f"The happy-birthday email has been sent to {birthday_person['email']} with the msg {new_data}")
else:
    print("The email has not been sent ! No one has a birthday today!")

Files to download:

Posted in Uncategorized
Write a comment