UiPath Save Attachments and Filter Example |Video upload date:  · Duration: PT6M52S  · Language: EN

Learn how to save email attachments with UiPath and apply sender and file type filters for reliable automation and fewer surprises

Filter by sender and file type to save only useful attachments in UiPath

Want to stop your downloads folder from becoming an evidence locker? This quick guide shows how to use UiPath to fetch email attachments and only keep the ones you actually want. We cover picking the right mail activity, retrieving messages, applying sender and file type filters, saving files safely, and handling errors without crying.

Pick the right mail activity

Use Get Outlook Mail Messages for a local Outlook client. Use Get IMAP Mail Messages for server based access. Configure account settings and the folder you want to scan before proceeding. Pick the wrong activity and the robot will politely tell you it does not know what you meant.

Retrieve and limit messages

Store the mail output in a variable called messages or something equally thrilling. Limit the number of messages to process so your first run does not turn into a weekend project. Sorting by date is handy when recent attachments matter more than receipts from 2012.

Filter messages and attachments

You have two good options. Use LINQ for concise filtering in a single expression or use a For Each with If checks for readability and step by step debugging.

messages.Where(Function(m) m.From.Address.ToLower.Contains("alice@company.com") AndAlso m.Attachments.Any(Function(a) a.Name.EndsWith(".pdf"))).ToList()

If LINQ makes you nervous use a For Each mail in messages then If checks on mail.From, mail.Subject or other properties. Then loop mail.Attachments and test extensions like .pdf or .xlsx to decide which attachments to save.

Save attachments safely

Drop a Save Attachments activity inside your message loop. Build the destination path with System.IO.Path.Combine and make sure the folder exists by calling System.IO.Directory.CreateDirectory(folder). If the directory does not exist UiPath will not create it on its own and you will have sad logs.

To avoid accidental overwrites add a timestamp or GUID to the file name. Example VB expression to prefix a timestamp

System.IO.Path.Combine(folder, DateTime.Now.ToString("yyyyMMddHHmmss") & "_" & attachment.Name)

Log errors and run dry tests

Wrap your save step in a Try Catch activity and log failures with Log Message or Write Line so you can trace what went wrong. Use a test mailbox during development and add a dry run boolean that only logs matched attachments without saving them. This prevents production clutter and saves your sanity.

Quick checklist

  • Choose Get Outlook Mail Messages or Get IMAP Mail Messages
  • Limit and sort messages by date
  • Filter by sender and attachment extension
  • Use Save Attachments and System.IO.Path.Combine to write files
  • Add a timestamp or GUID to file names to avoid overwrites
  • Wrap saves in Try Catch and log results for debugging
  • Test with a dry run mailbox before going live

Follow these steps and your UiPath flow will keep only useful attachments instead of hoarding everything in sight. If the robot still misbehaves add more logging and fewer expectations. Happy automating.

I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!

This is a dedicated watch page for a single video.