Purpose of the Code
This Python script automates the process of downloading attachments from Microsoft Outlook emails based on two key conditions:
-
The email was received today (from midnight to just before midnight)
-
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:
Recursively searches through all folders within the Inbox.
Filters only emails received today.
Matches keywords in subject lines (case-sensitive).
Downloads attachments to a specified local folder (you choose the location)
Automatically creates the folder if it doesnβt already exist
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.
View the Full Script on GitHub
Click here to view the full code on GitHub
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.