Hi there, I am Abhay
Recently on Friday, there is the birthday of my old school friend and due to some work, I forgot to wish him. He becomes so angry at me and we both have a big argument and a fight. at that time I realize that we are to busy in our life that we can't even wish our friends and relatives, that thought sparks the light in my head and I decided to make something using python which can help to send birthday messages and emails to all my friends and relatives at 12:00 clock sharp. so I search for it and find a way that can do my work.
In this blog, we are going to make a Birthday Wisher Script that sends birthday wishes to our friends at 12:00 clock sharp.
Let's start,
First thing if you are new to python and you have just opened the blog just for curiosity then you need to download python first.
Now, let's start by installing all the packages we need.
pip install pandas,email,smtlibOne more thing you need is an IDE or code editor for writing code. if you don't have any personal preference of yours, just download VS code.
Let's see the process we are going to follow
- Create an Excel file that contains the name, email, mobile number, message, year, Time.
- Using pandas fetch birthday year and date.
- Create a send_email function that can be used to send an email. it takes email, message, and subject as input.
- If the birthday year is equal to the current year then don't send the email because it is already been sent.
- if today is equal to a birthday day then check for the current time is equal to the wish time then send the email using the send_email function and increase the year column by one.
- Using windows scheduler makes the program run at every day 12:01 am or use some cloud service(pythonanywhere.com) to make it run every day at 12:01 am.
Create an Excel file
Just press the Windows key and type excel, and then create a new file and save it to the directory you are working with.
Add Rows and Columns to the Excel file
Now we need the add some data into the file. create 6 columns with name as name, email, mobile number, message, year, time.
name → names of our friends we want to send the emails or messages. email → emails of all our friends. mobile number → mobile numbers of all our friends. message → The birthday messages we want to send year → Enter the year in which we have wished him/her already. time → The time we want to wish them all.
We can add different — different values for all the rows and columns as per our choice.

For the future just add new rows with all six-column values for a new entry.
Import all the libraries that we need
import pandas as pd ##reading our excel file
import datetime ##for intracting with time and year
import smtplib ##for a connection between our gmail & python script
from email.message import EmailMessage ## sending emails
import os ## intracting with the systemWe are first writing code for sending emails only then we do some editing to convert it for messages also.
Creating a Function that sends the email
def sendEmail(to, sub, msg):
print(f"email to {to} \nsend with subject: {sub}\n message: {msg}")
email = EmailMessage()
email['from'] = 'Abhay Parashar'
email['to'] = f"{to}"
email['subject'] = f'{sub}'
email.set_content(f'{msg}')
with smtplib.SMTP(host='smtp.gmail.com', port=587) as smtp:
smtp.ehlo()
smtp.starttls()
smtp.login('Email','password')
smtp.send_message(email)
print("Email send")
passThis function takes the subject, message, and receiver email as arguments. then using EmailMessage class we are creating an object for this class. after that just setting up the value for to, from, subject and content. Then using smtplibwe are setting up a connection between your Gmail and our python script. then using our email and password just logging into the account and sending the email.
Reading the excel file using pandas
if __name__ == "__main__":
df = pd.read_excel("data.xlsx")
print(df)Here if __name__ == "main" block is used to prevent (certain) code from being run when the module is imported in another program.
Fetching Year Column for Comparision
Our main task is to create a script that can send birthday wishes to our friends so we need to make sure that the message we send will look like a legit message that is sent by us. To make this possible one thing is that we need to make sure that the email is sent only one time not more that one. for that we are just going to use the date-time module. using date-time we try to find our the current year and of the current year is equal to the year we put in our excel file then no email will be sent because we have already wished him, else an email is sent.
today = datetime.datetime.now().strftime("%d-%m") #print(type(today))
update = []
yearnow = datetime.datetime.now().strftime("%Y")Let's compare and send email
All done our whole code is ready. Now we have two options either we add it to the windows task scheduler or we add the script to some online cloud service that will run our script at 12:00 clock every day or according to your time.
For online Cloud use Pythonanywhere.com it is much easier and you can simply run your python script.
For windows Task scheduler just follow the below steps
- Just press the Windows key and type task scheduler.
- Then on the right side find create a new task and a new window will pop open.
- Just enter a Name. ex: Job_searcher
- Give the Location of your python file.
- Now add a new trigger from the trigger tab.
- Add the timings
- Go to the Actions tab
- Add the path of your python.exe file and after that the file of python file.
FULL CODE:
Thanks For Reading 😃