How to save only `.xlsx` and `.csv` email attachments and notify users of invalid files

Hi UiPath Community,

I’m automating processing of “Customer Invoices” emails. Here’s what I’ve done so far:

  • Loop through emails and attachments.
  • Filtered files using this condition:
{".xlsx", ".csv"}.Contains(System.IO.Path.GetExtension(currentAttachment.Name).ToLower())
  • Filtered filenames show correctly in the Output panel, but I’m unsure how to save only these files to a folder.

Additional requirement:

  • For other file types, automatically reply to the sender, asking them to share a valid .xlsx or .csv file.

Goal:

  1. Save only .xlsx and .csv attachments after filtering.
  2. Store them in a folder.
  3. Ignore other file types but notify the sender of invalid attachments.

Question:
What’s the best way to implement:

  • Filtering attachments
  • Saving only valid files
  • Logging saved files

How to work with this activity to save the right attachments:

To filter and save only .xlsx and .csv attachments, follow these steps:

  1. Filter Attachments: Use an If activity with this condition:

    {“.xlsx”, “.csv”}.Contains(System.IO.Path.GetExtension(currentAttachment.Name).ToLower())

  2. Save Valid Files: If the condition is true, use the Save Email Attachments activity to save the file to a folder.

  3. Log Saved Files: Use the Log Message activity to log the saved file’s path.

  4. Notify for Invalid Attachments: Use the Send Outlook Mail Message activity to reply to the sender if the file type is invalid (e.g., not .xlsx or .csv).

  5. Get Emails

  6. For Each Email
    3. For Each Attachment
    4. If attachment is .xlsx or .csv
    - Save Attachment
    - Log Message
    5. Else
    - Send Reply to Sender

This will save the correct files and notify senders about invalid attachments.

@Daniel_Oisebe

in filter by filename field you can use *.csv|*.xlsx this will save only these two extensions

cheers

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