Devlog: Automated Secret Santa Email System
Language: Python
Tools: VS Code, GitHub
Project Overview and Objective
I just made the project, it works! This project just required smtplib and ssl to establish a connection to Gmails servers, as well as python-dotenv to securely manage the sender’s email credentials without hardcoding passwords. As for the proper details on how this works, I will be including it in my README (that I’ve yet to make).
Challenges and Technical Roadblocks
There were a few bugs honestly. Here is what I ran into and how I solved them:
1. Environment Setup and Security Blocks
- The Problem: Windows initially wouldn’t recognize the pip command to install libraries, and standard email passwords were blocked by Gmail’s modern security protocols.
- The Solution: After some googling and reading forums, I realised I needed to bypass the Windows PATH issue by using python -m pip install. To fix the security block, I enabled 2-Step Verification on my Google account and generated a unique 16-character App Password specifically for this script. (Which I cannot show to anyone, you will not see it in my Github page).
2. Backend Shuffling Logic Error
- The Problem: Another problem with the backend logic, I used while loop to shuffle and assign the peoples names, something I realised was that it would delete items from the list using .pop(0) while shuffling inside the loop. This caused a logic error where people could be assigned to themselves, or multiple people could be assigned the same target.
- The Solution: In order to fix this I restructured the logic to create a separate clone of the participants list using .copy() and then implemented a while True loop that shuffles the target list and checks it. If anyone is matched with themselves, it automatically reshuffles before sending any emails.
Code Architecture
See the code below:
while True:
random.shuffle(targets)
matched_self = False
for i in range(len(participants)):
if participants[i][0] == targets[i][0]:
matched_self = True
break
if not matched_self:
break
So what’s next?
Just adding the README, testing to see of the project can handle variations or emails, (icloud, yahoo.com, microsoft, maybe like work or school organisations.)
And also adding an inbuilt condition to see if the email is valid, the program should see if an email is actually real. Not just try and send an email to someone like @gail.com or some other typo
Comments 0
No comments yet. Be the first!
Sign in to join the conversation.