How to creating Folder for outlook Attachments and saving them in seperate folder

Hi
I need to filter email’s and save the attachments in a seperate folder.
I have an excel which has ‘Country Name’.I am reading the excel, creating folder in country name and filtering the eamil subject with country name. However attachments are being saved in a single folder.
EX: Argentina has 2 mails which has 2 attachments each.
Colombia has 2 emails which has 3 attachments each.
Countries with attachments…

I need to save the Argentina attachments in Argentina folder. Chile attachments in Chile folder…

Is that possible. Please help me with this
Thanks. :handshake:

@abivanth.r,

Follow this approach.

  1. Download all the attachments in a central or common folder.
  2. Use For Each File In folder. While iterating checks the logic of country as you desire.
  3. Move the files to respective folder.

Thanks,
Ashok :slight_smile:

Hi @abivanth.r
image
Pass the Path details in the FolderPath property where you want to save the attachments.

Thanks @ashokkarale
i’ll let you knoe if it works.
Thanks again. :handshake:

1 Like

I haven’t practiced with this activity. Can you please elaborate the method

Hi @abivanth.r ,

Could you please share me your workflow?

Regards,
Vinit Mhatre

Hi @abivanth.r ,

Can you please explain what is the criteria of filtering the mail messages…are we filtering the mail based on a keyword present in the subject?

I have implemented the Folder creation and saving the attachments logic in the below workflow.
Saving Outlook Attachment in loop.zip (11.6 KB)

Hope it helps you out!

Dispatcher-2.xaml (13.6 KB)
This is working.
The only concern is i need to put the attachments in their respective folders

we’re filtering the subject by an excel file. Let me attach the excel and .xaml for your reference
Counrty list 3.xlsx (9.3 KB)
Dispatcher-2.xaml (13.6 KB)

What you need in this ? Already workflow is built as per your requirement

The attachments are not being saved in their respective country folder.
I need to save them like this. this is the folder format


right now all the attachments are being saved in “EmailAttachment/Argentina”
I need to save them as shown in picture

Hi @abivanth.r ,

Update the path as below

"C:\Users\abivanth.r\OneDrive - HCL TECHNOLOGIES LIMITED\Documents\EmailAttachments\"+Row(“Country Name”).ToString+"\"+now.ToString("dd-MM-yyyy")

Regards,
Vinit Mhatre

It is getting in the date folder. but all countries attachment are saved in a bunch

Can you explain in simple word like what is your expected output and what output you are getting now


This is how i want the attachments to be the respective country folder.
what i am getting is

Hi @abivanth.r ,

Update the path into marked positioned

"C:\Users\abivanth.r\OneDrive - HCL TECHNOLOGIES LIMITED\Documents\EmailAttachments\"+Row(“Country Name”).ToString+"\"+now.ToString("dd-MM-yyyy")

Regards,
Vinit Mhatre

Changed it… but the output is still the same

This document outlines a professional UiPath workflow designed to automate the process of fetching emails with attachments from Outlook, creating separate folders for each email based on its subject, and saving the attachments within those folders. The approach utilizes built-in UiPath activities, adhering to their guidelines against custom activities.

Workflow Structure:

  1. Retrieve Emails:
  • Employ the Get Outlook Mail activity to retrieve emails from a specified Outlook folder or based on defined criteria (e.g., unread emails, emails with specific keywords).
  1. Iterate Through Emails:
  • Implement a For Each activity to iterate through each email retrieved in step 1.
  1. Check for Attachments:
  • Inside the For Each loop, utilize an If activity to check if the current email has attachments. This can be achieved by evaluating the MailMessage.Attachments.Count property. Only emails with attachments proceed further.
  1. Dynamic Folder Creation:
  • Within the If activity (true branch), construct a dynamic folder path for the current email’s attachments. Here’s how to achieve this professionally:
    • Define a base folder path variable (e.g., baseFolderPath = @"C:\Attachments\") to store the root location for saving attachments.
    • Extract the subject of the current email using MailMessage.Subject.
    • Employ System.IO.Path.Combine to seamlessly create the full folder path by concatenating the base folder path with the email subject. This ensures proper handling of directory separators across different operating systems.
    • Enclose the folder creation in a Try Catch block to gracefully handle potential exceptions during directory creation (e.g., insufficient permissions, existing folder with the same name).
  1. Save Email Attachments:
  • Within the If activity’s true branch, leverage the Save Mail Attachments activity. Configure the activity’s properties as follows:
    • Set the FolderPath property to the dynamically created folder path. This ensures attachments are saved in the designated folder for that particular email.
    • Bind the MailMessage property to the current email object being processed in the For Each loop.
    • Execute the Save Mail Attachments activity to initiate downloading and saving all attachments from the current email into the corresponding folder.
  1. Error Handling:
  • Implement appropriate error handling mechanisms throughout the workflow. Utilize Try Catch blocks to capture exceptions that might arise during folder creation, file operations, or interaction with Outlook. Log or display meaningful error messages for better troubleshooting.

I completed the workflow.
result is getting correctly.
but if i use filter in ‘get outlook mail activity’ it is not reading any mails?
how can i fix it
attaching my .Xaml for reference
Dispatcher-2.xaml (20.7 KB)

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.