Automating Outlook Attachment Downloads Based on Subject and Date using Python 🐍

:receipt: Purpose of the Code

This Python script automates the process of downloading attachments from Microsoft Outlook emails based on two key conditions:

  1. The email was received today (from midnight to just before midnight)

  2. The subject line contains a specific keyword (e.g., daily reports or project files)

It navigates through the entire Outlook Inbox, including all subfolders, looking for matching emails. When it finds one, it saves all attachments from that message to a designated download folder on your system (e.g., D:\Downloaded_Attachments or any path you define).

Highlights of the script:

:repeat: Recursively searches through all folders within the Inbox.

:spiral_calendar: Filters only emails received today.

:abc: Matches keywords in subject lines (case-sensitive).

:open_file_folder: Downloads attachments to a specified local folder (you choose the location)

:white_check_mark: Automatically creates the folder if it doesn’t already exist

:warning: Includes basic error handling to report issues per folder

This is ideal for automating tasks like downloading daily status reports, automated logs, or other recurring files that arrive in email.

:link: View the Full Script on GitHub

:point_right: Click here to view the full code on GitHub

:memo: Conclusion

This Python script streamlines the process of downloading email attachments from Outlook, focusing on today’s emails and filtering by a specific keyword in the subject. With its recursive search through all inbox folders, automatic creation of the destination folder, and seamless saving of attachments, this script is an efficient tool for automating daily tasks like downloading reports or logs. It can be easily customized to handle different keyword searches, file types, or sender filters, making it a versatile solution for anyone looking to automate their email processing workflow.