Automate Your Work with AI: How to Summarize Emails into an Excel File with a Single Click

There are countless ways in which AI can help you automate tedious tasks. In this article, I’ll show you how, with the help of ChatGPT (or any other large language model tool), you can create a simple program that summarizes your emails and saves them in a CSV or Excel file—all done with just one click (well, almost!).

Most of us aren’t programmers, right? We don’t spend our days writing code or developing software, and we may not even have the skills (or the interest!) to do so. But what if I told you that generative AI tools like ChatGPT can make it incredibly easy to create simple programs tailored to your specific needs? These tools can take the complexity out of coding, opening the door for anyone to automate routine tasks, even with no coding experience.

Give It a Try

Think of a task that’s usually manual and repetitive—something boring that you’d love to automate. With generative AI, you can create a little program that handles it for you in just a few steps.

In this example, I’ll walk you through how to use ChatGPT to create a Python program that exports emails from your inbox and saves them as an Excel file on your desktop. For this specific example, we’ll be working on a Mac, using Apple’s default Mail app. But don’t worry—the approach can easily be adapted to work with other email clients or operating systems. The key is simply starting with a clear prompt in ChatGPT about what you want to achieve, and then letting it guide you through the process of building the code.

Now, keep in mind that the solution might not be perfect right away. You may need to make adjustments, debug, and refine it through a bit of trial and error. But by working with ChatGPT, you'll eventually develop a program that works as you need it to. Once it’s up and running, you'll be able to execute it with just a click, automating a previously time-consuming task!


Now, let’s dive into our email automation example.


Prompt (initial): Help me to create a little programme for my Mac which extracts a list of Emails from my Mail app, based on emails received in the the last 7 days. A list of emails (Sender Email, Sender Name, Subject) then need to be saved as a csv file on my Desktop.


Prompt (refined): Write a Python script that retrieves emails from the Apple Mail app using AppleScript. The script should fetch all emails from the inbox received in the last 7 days, extracting the subject, sender, and received date for each email. Once the emails are fetched, the script should save the data into an Excel file on the user's desktop, with each email's subject, received date, and sender stored in separate columns. Use the openpyxl library to handle Excel file creation, and execute the AppleScript using the subprocess module. Ensure that the Excel file is titled "my_emails.xlsx" and is placed on the desktop.


At first, I started with a simpler (initial) prompt. But as I worked through it with ChatGPT, we refined the prompt together. The final version included the use of AppleScript to retrieve emails and the openpyxl Python library to generate an Excel file. I’ve provided this refined prompt here to save you time, but feel free to start from your own, less refined prompt.

Next Steps: Get Your Own Program Running (Mac)

If you’d rather skip the coding process altogether, you can simply download the Python script that ChatGPT helped me generate and run it on your Mac. If you prefer to try it yourself, use the prompt above to start the process in ChatGPT, and follow the steps it provides. The great thing about working with these tools is that they can guide you through every step of the process, offering suggestions and helping you debug along the way.

Step 1: Install Python (if not already installed)

  1. Check if Python is installed:

    • Open the Terminal on your Mac (search for "Terminal" using Spotlight or find it in Applications > Utilities).

    • Type python3 --version and press Enter.

    • If you see a version number (e.g., Python 3.9.1), Python is already installed, and you can skip to Step 2.

    • If you don’t see a version or get an error, you’ll need to install Python.

  2. Install Python:

    • Go to the official Python website and download the latest version for macOS.

    • Open the downloaded file and follow the installation instructions.

Step 2: Install Required Libraries

The script uses a Python library called openpyxl to create the Excel file. Here’s how to install it:

  1. Open Terminal:

    • Go to Applications > Utilities > Terminal.

  2. Install openpyxl:

    • In the Terminal, type the following command and press Enter:

      pip3 install openpyxl

    • This will install the required library for working with Excel files.

Step 3: Download or Copy the Python Script

  1. Get the script:

    • If you’ve downloaded the script I provided, save it somewhere easy to find, like your Desktop.

    • If you’re creating the script with ChatGPT, copy the code and paste it into a new text file on your computer.

  2. Save the file:

    • Save the file with the name email_to_csv.py and place it on your Desktop.

Step 4: Run the Python Script

  1. Open Terminal:

    • Open the Terminal app again (Applications > Utilities > Terminal).

  2. Navigate to the Desktop:

    • In the Terminal, type the following command and press Enter:

      cd ~/Desktop

  3. Run the script:

    • Now, type the following command and press Enter:

      python3 email_to_csv.py

  4. Allow permissions (if prompted):

    • If this is the first time you're running the script, you might need to allow permission for Apple Mail to be accessed by Python. Follow the on-screen instructions.

Step 5: Check Your Desktop for the Excel File

  • Once the script runs, it will automatically save an Excel file called my_emails.csv on your desktop.

  • Open it up to see your email summary in an easy-to-read spreadsheet format!


Troubleshooting

  • Permission errors: If you get permission-related errors, ensure you’ve allowed access to the Mail app in your Mac’s System Preferences > Security & Privacy.

  • Errors running the script: Double-check that you’ve followed the instructions to install Python and openpyxl properly. If in doubt, restart the Terminal and try again.

  • Get ChatGPT to help you: If you encounter any issues when running the script, simply head back to ChatGPT and describe the issue. I suggest to take screenshots and pasting to ChatGPT as that way ChatGPT can see in details of what is happening and you wont need to type as much.

Good luck!

Agnes


Make it stand out

Whatever it is, the way you tell your story online can make all the difference.

Previous
Previous

AI Coding Assistants for Data Analysis.

Next
Next

25 Use Cases for Using ChatGPT and other Gen AI tools as a Data Analyst