Tutorials

Send Birthday Wish as SMS/Mail with Python 3 Fast2SMS API

Python 3 Fast2SMS API Bot to Send Birthday Wish as SMS or Mail to Multiple Contacts on Phone in Command Line

code.py

# import required packages
import pandas as pd
import datetime
import smtplib
import time
import requests
from win10toast import ToastNotifier

# your gmail credentials here
GMAIL_ID = 'your_email_here'
GMAIL_PWD = 'your_password_here'

# for desktop notification
toast = ToastNotifier()

# define a function for sending email
def sendEmail(to, sub, msg):

  # connection to gmail
  gmail_obj = smtplib.SMTP('smtp.gmail.com', 587)
  
  # starting the session
  gmail_obj.starttls()  
  
  # login using credentials
  gmail_obj.login(GMAIL_ID, GMAIL_PWD)
  
  # sending email
  gmail_obj.sendmail(GMAIL_ID, to,
        f"Subject : {sub}\n\n{msg}")
  
  # quit the session
  gmail_obj.quit()
  
  print("Email sent to " + str(to) + " with subject "
    + str(sub) + " and message :" + str(msg))
  
  toast.show_toast("Email Sent!" ,
          f"{name} was sent e-mail",
          threaded = True,
          icon_path = None,
          duration = 6)

  while toast.notification_active():
    time.sleep(0.1)

# define a function for sending sms  
def sendsms(to, msg, name, sub):

  url = "https://www.fast2sms.com/dev/bulk"
  payload = f"sender_id=FSTSMS&message={msg}&language=english&route=p&numbers={to}"
  
  headers = {
    'authorization': "API_KEY_HERE",
    'Content-Type': "application/x-www-form-urlencoded",
    'Cache-Control': "no-cache",
    }

  response_obj = requests.request("POST", url,
                data = payload,
                headers = headers)
  print(response_obj.text)
  print("SMS sent to " + str(to) + " with subject :" +
    str(sub) + " and message :" + str(msg))
  
  toast.show_toast("SMS Sent!" ,
          f"{name} was sent message",
          threaded = True,
          icon_path = None,
          duration = 6)

  while toast.notification_active():
    time.sleep(0.1)

# driver code
if __name__=="__main__":

  # read the excel sheet having all the details
  dataframe = pd.read_excel("excelsheet.xlsx")
  
  # today date in format : DD-MM
  today = datetime.datetime.now().strftime("%d-%m")
  
  # current year in format : YY
  yearNow = datetime.datetime.now().strftime("%Y")
  
  # writeindex list
  writeInd = []                        

  for index,item in dataframe.iterrows():
  
    msg = "Many Many Happy Returns of the day dear " + str(item['NAME'])
        
    # stripping the birthday in excel
    # sheet as : DD-MM
    bday = item['Birthday'].strftime("%d-%m")  
    
    # condition checking
    if (today == bday) and yearNow not in str(item['Year']):
      
      # calling the sendEmail function
      sendEmail(item['Email'], "Happy Birthday",
          msg)
      
      # calling the sendsms function
      sendsms(item['Contact'], msg, item['NAME'],
          "Happy Birthday")
      
      writeInd.append(index)                

  for i in writeInd:
  
    yr = dataframe.loc[i,'Year']
    
    # this will record the years in which
    # email has been sent
    dataframe.loc[i,'Year'] = str(yr) + ',' + str(yearNow)      

  dataframe.to_excel('excelsheet.xlsx',
        index = False)
Furqan

Well. I've been working for the past three years as a web designer and developer. I have successfully created websites for small to medium sized companies as part of my freelance career. During that time I've also completed my bachelor's in Information Technology.

Recent Posts

AppCleaner vs Pearcleaner: The Ultimate 2025 Comparison Guide

Quick Takeaway: For users seeking a no-frills, ultra-straightforward uninstaller, AppCleaner’s drag-and-drop simplicity and SmartDelete automation make it…

October 21, 2025

Mem0 Alternatives: Complete Guide to AI Memory Solutions in 2025

Looking for the right AI memory solution but not sure if Mem0 fits your needs?…

October 21, 2025

Splashtop Alternatives: Top Remote Desktop Solutions for 2025

Looking for better remote access options? You're not alone. Many IT teams and businesses are…

October 21, 2025

Same.new Alternatives: Complete Guide to AI Web App Builders in 2025

Looking for alternatives to Same.new? You're not alone. While Same.new promises to clone websites and…

October 21, 2025

Coolify vs Dokploy: I Tested Both — Here’s What You Need to Know

If you're paying steep bills to Heroku, Vercel, or Netlify and wondering if there's a…

October 21, 2025

MiniMax-M1 vs GPT-4o vs Claude 3 Opus vs LLaMA 3 Benchmarks

MiniMax-M1 is a new open-weight large language model (456 B parameters, ~46 B active) built with hybrid…

August 31, 2025