The Palos Publishing Company

Follow Us On The X Platform @PalosPublishing
Categories We Write About

Birthday SMS Sender Script

Here’s a Birthday SMS Sender Script in Python that reads contact details (name, phone number, and birthday) from a CSV file and sends SMS via Twilio API. The script checks if today matches any contact’s birthday and sends a personalized message.

python
import csv from datetime import datetime from twilio.rest import Client # Twilio credentials (replace with your actual credentials) TWILIO_ACCOUNT_SID = 'your_account_sid' TWILIO_AUTH_TOKEN = 'your_auth_token' TWILIO_PHONE_NUMBER = '+1234567890' # Path to the CSV file containing contact details CONTACTS_CSV = 'contacts.csv' # Initialize Twilio client client = Client(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN) def read_contacts(file_path): contacts = [] with open(file_path, mode='r', newline='', encoding='utf-8') as file: reader = csv.DictReader(file) for row in reader: contacts.append({ 'name': row['Name'], 'phone': row['Phone'], 'birthday': row['Birthday'] # Format: YYYY-MM-DD }) return contacts def send_birthday_sms(name, phone): message = f"Happy Birthday, {name}! 🎉 Wishing you a day filled with happiness and a year filled with joy." try: client.messages.create( body=message, from_=TWILIO_PHONE_NUMBER, to=phone ) print(f"Sent to {name} at {phone}") except Exception as e: print(f"Failed to send to {name}: {e}") def check_and_send_birthday_wishes(): today = datetime.now().strftime('%m-%d') contacts = read_contacts(CONTACTS_CSV) for contact in contacts: try: contact_birthday = datetime.strptime(contact['birthday'], '%Y-%m-%d').strftime('%m-%d') if contact_birthday == today: send_birthday_sms(contact['name'], contact['phone']) except ValueError: print(f"Invalid date format for {contact['name']}") if __name__ == '__main__': check_and_send_birthday_wishes()

CSV Format (contacts.csv)

csv
Name,Phone,Birthday John Doe,+12345678901,1990-05-18 Jane Smith,+12345678902,1985-07-24

Notes

  • Ensure the Twilio number has permissions to send SMS to the target country.

  • Schedule this script daily using cron (Linux/macOS) or Task Scheduler (Windows).

  • Handle rate limits or message quotas in production by batching or using retry logic.

Let me know if you want a version using a different SMS API or database backend.

Share this Page your favorite way: Click any app below to share.

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Categories We Write About