Saving email attachments manually and filing them into dedicated directories quickly becomes tedious. With Microsoft Power Automate Desktop (PAD), you can build an automated workflow that fetches unread emails, downloads their attachments, and dynamically creates folders named after each file to keep your local storage tidy.
Workflow Overview
The automation performs the following sequence:
Opens Microsoft Outlook.
Retrieves unread emails from the inbox and saves attached files to a temporary directory.
Extracts the base filename and the complete filename using Regular Expressions (Regex).
Creates a new subfolder named after the attachment.
Moves the downloaded attachment into its newly generated folder.
Step-by-Step Implementation
Step 1: Launch Outlook & Retrieve Messages
Add the Launch Outlook action to store the session instance in
%OutlookInstance%.Add the Retrieve email messages from Outlook action:
Outlook Instance:
%OutlookInstance%Account:
your-email@domain.comMail folder:
InboxRetrieve:
Unread email messages onlyAttachments: Set to
Save attachmentsSave attachments into: Specify your download directory (e.g.,
C:\Users\Username\Downloads\Outlook attachments\)Variables Produced:
%RetrievedEmails%
Step 2: Extract File Paths and Names Using Regex
To handle and relocate the file properly, we extract both the file name without its extension (to name the folder) and the full file name with extension (to move the file).
Assign Variable:
Set
%NewVar%to%RetrievedEmails[0].Attachments[0].FullName%.Parse File Name Without Extension (For Folder Name):
Action:
Parse textText to parse:
%NewVar%Text to find:
[^\\]+(?=\.[^.]+$)Is regular expression:
EnabledVariables Produced:
%Match%
Parse File Name With Extension (For Moving the File):
Action:
Parse textText to parse:
%NewVar%Text to find:
[^\\]+$Is regular expression:
EnabledVariables Produced:
%varFileNameMatch%
Step 3: Create Dynamic Folder & Move Attachment
Create Folder:
Create new folder into:
C:\Users\Username\Downloads\Outlook attachmentsNew folder name:
%Match%Variables Produced:
%NewFolder%
Move File:
File(s) to move:
C:\Users\Username\Downloads\Outlook attachments\%varFileNameMatch%Destination folder:
C:\Users\Username\Downloads\Outlook attachments\%Match%\If file exists:
Overwrite(or rename according to your preference)
Key Benefits
Zero Manual Effort: Automatically scans incoming emails and sorts attachments hands-free.
Organized Storage: Prevents clutter by generating isolated folders per attachment automatically.
Reusable Logic: The regular expression patterns can be repurposed across other file-handling flows in Power Automate Desktop.
Comments
Post a Comment