How to Automate Birthday Wishes with Python

Automate birthday wishes with Python and Excel! Step-by-step guide using Pandas, smtplib, and Gmail to send personalized birthday wishes.

Ever wished you could automate birthday wishes for your friends, teammates, or clients? This guide will show you how to build a Birthday Email Automation Tool using Python, Excel, and Gmail — with just a few lines of code!

✅ This tutorial covers:

  • Reading birthday data from Excel using Pandas
  • Matching today’s date with birthdates
  • Sending personalized emails using SMTP
  • Updating the Excel sheet so we don’t send duplicate wishes

Let’s dive in!


🧰 What You’ll Need

Before we start, make sure you have:

  • Python 3 installed
  • A Gmail account (with less secure apps enabled or an app password)
  • An Excel file (data.xlsx) with the following columns:
    • Name
    • Email
    • Birthday (in dd-mm-yyyy format)
    • Dialogue (personal message)
    • LastWishedYear

🗂 Step 1: Import the Libraries

import pandas as pd
import datetime
import smtplib
import os

Let’s quickly explain:

  • pandas helps you read and manipulate Excel files.
  • datetime is used to check today’s date.
  • smtplib helps you send emails using Gmail.
  • os handles file paths and directories.

📁 Step 2: Set the Directory for Your Automated Birthday Wishes Script

current_path = os.getcwd()
print(current_path)
os.chdir(current_path)

This makes sure the script works in the same folder where your Excel file (data.xlsx) is saved.


✉️ Step 3: Input Your Gmail Details

GMAIL_ID = input("Enter your email: ")
GMAIL_PSWD = input("Enter password for your email mentioned above: ")

This collects your Gmail credentials. Pro Tip: You can use environment variables or getpass for security.


📬 Step 4: Define the Email Sender Function

def sendEmail(to, sub, msg):
print(f"Email to {to} sent: \nSubject: {sub} ,\nMessage: {msg}")
s = smtplib.SMTP('smtp.gmail.com', 587)
s.starttls()
s.login(GMAIL_ID, GMAIL_PSWD)
s.sendmail(GMAIL_ID, to, f"Subject: {sub} \n\n {msg}")
s.quit()

This function:

  • Connects to Gmail SMTP server
  • Logs into your email
  • Sends a message to the recipient with a subject and body

📊 Step 5: Read the Excel File

df = pd.read_excel("data.xlsx")

This loads the Excel data into a DataFrame. Every row is one person’s info.


🕒 Step 6: Match Today’s Date to Automate Birthday Wishes on Time

today = datetime.datetime.now().strftime("%d-%m")
yearNow = datetime.datetime.now().strftime("%Y")

These lines get:

  • today: Current date in dd-mm format
  • yearNow: The current year, e.g., 2025

🎯 Step 7: Send Personalized Emails to Automate Birthday Wishes

writeInd = []

for index, item in df.iterrows():
bday = item['Birthday']
bday = datetime.datetime.strptime(bday, "%d-%m-%Y")
bday = bday.strftime("%d-%m")

if(today == bday) and yearNow not in str(item['LastWishedYear']):
sendEmail(item['Email'], "Happy Birthday", item['Dialogue'])
writeInd.append(index)

Explanation:

  • Loop through each row in Excel
  • Convert the Birthday string to a date
  • Check if today matches their birthday
  • Ensure we haven’t already wished them this year
  • Send an email if both conditions are true
  • Track the index to update the year later

📝 Step 8: Update “LastWishedYear” in Excel

if writeInd != None:
for i in writeInd:
oldYear = df.loc[i, 'LastWishedYear']
df.loc[i, 'LastWishedYear'] = str(oldYear) + ", " + str(yearNow)

This keeps a record of all years the person has been wished — so we never send repeats in the same year.


💾 Step 9: Save the Updated Excel Sheet

df.to_excel('data.xlsx', index=False)

Saves all changes back to data.xlsx.


📌 Your Final Excel Template Should Look Like:

NameEmailBirthdayDialogueLastWishedYear
John Doejohn@email.com20-07-1990Have a blast, John!2023
Jane Smithjane@email.com20-07-1995Shine bright, Jane!2022, 2024

📝 Make sure the Birthday is in dd-mm-yyyy format.


🔐 Security Note

Avoid hardcoding passwords. Instead:

  • Use Python’s getpass module
  • Store secrets in environment variables
  • Or use Gmail’s App Passwords

✅ Conclusion: Why You Should Automate Birthday Wishes with Python

There you have it — your own birthday email bot, powered by Python and Excel!

Not only will this save you time, but it’ll also make you the most thoughtful person in the room (well, inbox 💌).


💡 What’s Next?

  • Convert this to a Streamlit app
  • Add HTML-formatted emails with images
  • Schedule the script using Task Scheduler or cron

Want more beginner-friendly projects like this?

👉 Check out how to Predict Your Salary with Python
👉 Or Build an AI Quote Generator


💬 Have Questions?

Drop a comment below, share this with your Python gang, or get in touch with us at Ossels AI! 🚀

Posted by Ananya Rajeev

Ananya Rajeev is a Kerala-born data scientist and AI enthusiast who simplifies generative and agentic AI for curious minds. B.Tech grad, code lover, and storyteller at heart.