Site icon Taslim Okunola

Sharing My USPS Mail Alerts Apps Script

an image of multiple mailboxes in a row

Photo by Paula Hayes on Unsplash

tl;dr – USPS Mail Alerts (GitHub repo here) is a Google Apps Script that automatically creates Google Tasks reminders based on USPS Informed Delivery emails.

I remember the first time I stumbled across Google Apps Script in college, my mind was blown to pieces. The sheer possibilities of extending the capabilities of your Google apps was inviting, even though I couldn’t write a lick of code back then (I still can’t write now. I just understand it better). Fast-forward to today, and the itch to build cool stuff never left me. The twist is that LLMs can now write code for you. I started by conjuring complex Google Sheets formulas with AI chatbots, then quickly graduated to building Apps Scripts. It’s been a wild journey. And today, I’d love to share one of those projects with you—my USPS Mail Alerts Apps Script.

The Idea

It all started in the summer of 2023. I had just moved to the United States six months prior and signed up for a free USPS service called Informed Delivery. They basically send you an email in the morning if you have any physical mail heading your way that day. Being the diligent mailbox checker that I am, this was a lifesaver because it saved me from frequent trips to a disappointingly empty mailbox.

But then, I thought, what if I could make this process even smoother? That’s when the LLM craze hit, and I decided to build something nifty to make my mail-checking experience better.

v1 – Check email and create task

My initial idea was simple: build an Apps Script to scan those Informed Delivery emails and create a task in Google Tasks if a new email showed up. Here’s the flow I came up with::

See the code snippet for v1:

function createTaskForNewEmails() {
  var labelName = 'a--notify/2-informed delivery';
  var taskTitle = 'Pick up mails'; //

  var label = GmailApp.getUserLabelByName(labelName);
  if (label === null) {
    console.log('Label not found.');
    return;
  }

  var threads = label.getThreads();

  for (var i = 0; i < threads.length; i++) {
    var today = new Date();

    var thread = threads[i];
    var messages = thread.getMessages();
    var lastMessage = messages[messages.length - 1];

    var messageDate = lastMessage.getDate();

      // Create a new task
      var task = Tasks.newTask();
      task.title = taskTitle;
      task.due = dueDate.toISOString();

      // Save the task
      var taskListId = 'taskID'; // Replace with your task list ID
      Tasks.Tasks.insert(task, taskListId);

      break; // Exit the loop after creating a task for the first new email
    }
  }
}

You can already tell some of the problems with v1:

v2 – Make it better!

In just one year, the models got incredibly better. Everyone was experimenting with more complex apps including me. I even built a fortune cookie app but I digress. Inspired by how far AI-assisted coding had come, I redesigned my mail alert apps script and fired up my AI chatbots to help code it.

What I improved:

Today, I’m open-sourcing v2 of this script so we can all improve our mailbox-checking experience and optimize our laziness (I mean efficiency 😂) together. See the GitHub repo here. You can also find the README in the GitHub repo, with straightforward instructions even for folks who don’t code.

Let me know what you think! And if you have any suggestions or improvements, feel free to contribute.

Stay building! 🚀

Comment on Hacker News

Exit mobile version