HappyBirthday.sh

Wishing Happy Birthdays Autonomously

Happy Birthday!!!

Introduction

   Ever wanted to wish your friends and family a happy birthday, but accidentally forget the date? They might be okay with a belated email - but would you be satisfied? Fret no further, because this little script will be churning out birthday greetings at a steady rate of one per year for all your loved ones (and those you tolerate but prefer to be on their good side).

Features

  • Supports simple plain-text for homely wishes and HTML for extravagantly designed birthday bashes.
  • Images, gifs, and other forms of media can be embedded (kind of) for aesthetic appeal.
  • Allows for personalization of emails such as greeting by first names and using specific images to be utilized.
  • Designed to be set up as a cron job for effortless greetings.

Dependencies

  • sendmail/mailx/mutt - For sending mail via the command line
  • SQLite3 (Recommended) - For database management without using a SQL server

Demonstration

   Ever since I learned about setting up scripts to be run autonomously using the cron daemon, I immediately wanted a script to send happy birthday emails to my friends. So that's what I did. It only supported a plain-text file and everyone received the same email, but it worked like a charm. Only during the following year when a person was to be sent that same email twice did I decide to upgrade. Thus, this is what I came up with.

Plain-text email HTML email
Plain-old plain-text Hip HTML

   However, with another year's worth of programming expertise, I wanted to up the ante. Personalization was the goal - the ability to have happy birthday emails differ based on the recipient. For example, I wanted my lab coworkers to get a somewhat research themed email versus my friends which I could include some dank NSFW content (or SFW if I so desire). I decided to use a SQL backend to handle more complicated personalization cases. SQLite3 was a tool I used recently at the time and I was quite impressed that an active server was unnecessary to utilize it. You may believe that increased computational time is its detriment but for this script, only a few tables of non-big data sizes are required; thus, this is a non-issue.

   To begin, let's setup some emails to use. Once again, you can use a flat text file or HTML. The latter allows you to link images, gifs, etc. Orchestrate the HTML as you would normally, but for the src attributes within img tags, let the source be cid:NAME, where one substitutes the placeholder NAME with a more suitable phrase. Then, when constructing the SQL database, this NAME will be associated with some object which holds the actual location of the media. Thus, upon execution of the main script, all of these cid's will be replaced with their respective URLs. This is a level of personalization as a particular person can recieve an email with photos tailored towards them.

   Once those beautiful emails have been transcribed, we add these to our database, as well as the recipients of said emails, their birth dates, URLs of images, etc. The only finicky detail is how to initialize such a database and maintain it without a server continuously running. Thus, I came up with instantiateDB.sh, which when run will create a target database for birthday.sh to extract details from. One can easily hand-edit the former script and execute it for updating information. A bit annoying without a GUI, but it should suffice. Note that for this part, one should be a bit familiar with adding entries into a SQL database, but hopefully the examples provided should be somewhat explanatory. For further help, I've drafted a crude ER diagram showing how each table is linked to one another.

ER diagram Installation into cron table
Personalization roadmap Last step before kicking up your feet

   When everything is set up, test out the birthday.sh script using your email as the recipient as to see if it is suitable (and pray that your email browser isn't malicious and massacres your meticulous layout). If you used HTML, check out this guide which helps iron out some pernicious problems perpetuated with particular email projection providers. When satisfied with your hard work, try adding the script as a cron job (tutorial here) and set the execution time a minute from now as a secondary test. If all looks well, re-edit the job to execute at a convenient time everyday. Now we're done! Enjoy your autonomous happy birthday greetings!

   A little aside note on embedding images in emails. You technically still can embed raw image data within emails (encoded in base64) using the cid method, but as I found out the hard way, this is not supported on all email browsers. In particular, Microsoft Outlook will briefly display a broken image link before making it disappear all together (with good ole display:none). Supposedly, this is used for spam emails that clog themselves with flashy advertisements. It also discourages embedding as a practice since inserting raw image data leads to a larger payload and expends more bandwidth, which afaik, isn't cached. I still keep the vestigial cid as an homage to the strenous research that I conducted to send a god forsaken email with embedded images via Unix's sendmail. Believe me, when you've landed yourself looking at a 1970's manual on a forgotten IBM webpage attempting to elucidate the syntax for boundaries and MIME-type declarations, you've gone too far Alice.</rant>