Skip to main content
Solved

Seeking advice on downloading email attachments filtered by file name/extension

  • May 27, 2026
  • 5 replies
  • 30 views

Uzumaki
Forum|alt.badge.img+2

In my research it doesn’t seem like it is possible to filter emails by attachment extension or name before downloading them using the out of the box email/outlook packages. I wanted to ask here if there was perhaps another way that I am overlooking.

Its possible using graph API so that is my back up if all else fails.

Best answer by Uzumaki

For anyone curious, I decided that the graph API is the best solution for this. The same client ID/secret used to connect to the O365 outlook package had graph access and that allows me to view attachment names before downloading.

5 replies

rbkadiyam
Premier Pathfinder | Tier 7
Forum|alt.badge.img+6
  • Premier Pathfinder | Tier 7
  • May 27, 2026

@Uzumaki 

 

Option #1 :  Email Metadata First, Then Inspect Attachments  : This is usually the cleanest Automation Anywhere-native solution.

Use:  Email → Get all emails
        Apply normal filters (subject, sender, folder, unread, etc.)
        Loop through returned emails
For each email:
Use:
        Get attachments
        or Save attachments to temp folder
Check:
        Attachment name
        Extension
        Pattern matching
        Only process matching files
Example Logic
FOR EACH email

    Get attachment list

    FOR EACH attachment

        IF attachment.name EndsWith ".csv"
            Process attachment
        END IF

    END LOOP

END LOOP


Option #2 — Save to Temp Folder + File Filtering

This is commonly used in enterprise bots.

Steps
1. Save all attachments
Use:
    Outlook → Save attachments
Save into:
    C:\Temp\MailAttachments\

2. Use File Package

Then:
    Loop files in folder
    Filter using:
    *.xlsx
    *.pdf
    invoice_*.csv


Uzumaki
Forum|alt.badge.img+2
  • Author
  • Navigator | Tier 3
  • May 27, 2026

@Uzumaki 

 

Option #1 :  Email Metadata First, Then Inspect Attachments  : This is usually the cleanest Automation Anywhere-native solution.

Use:  Email → Get all emails
        Apply normal filters (subject, sender, folder, unread, etc.)
        Loop through returned emails
For each email:
Use:
        Get attachments
        or Save attachments to temp folder
Check:
        Attachment name
        Extension
        Pattern matching
        Only process matching files
Example Logic
FOR EACH email

    Get attachment list

    FOR EACH attachment

        IF attachment.name EndsWith ".csv"
            Process attachment
        END IF

    END LOOP

END LOOP


Option #2 — Save to Temp Folder + File Filtering

This is commonly used in enterprise bots.

Steps
1. Save all attachments
Use:
    Outlook → Save attachments
Save into:
    C:\Temp\MailAttachments\

2. Use File Package

Then:
    Loop files in folder
    Filter using:
    *.xlsx
    *.pdf
    invoice_*.csv

Thanks for the feedback. However, my goal is to filter by extension before downloading anything. For security purposes, I want to know the file extensions being downloaded first rather than downloading everything and then deleting what I don’t need.


rbkadiyam
Premier Pathfinder | Tier 7
Forum|alt.badge.img+6
  • Premier Pathfinder | Tier 7
  • May 27, 2026

 ​@Uzumaki 

 

Step 1: Use “Get Email / List Emails” 

Depending on your package (Outlook / IMAP / Gmail connector):

You should first retrieve emails with:

  • Subject
  • Sender
  • Email ID
  • Attachment names 

Most AA email actions return something like:

  • AttachmentNames → array/list of file names
  • AttachmentCount

 

Attachments:
- invoice.pdf
- malware.exe
- report.xlsx

Step 2: Filter in Bot BEFORE Download

Use a loop + condition:

FOR each attachmentName in AttachmentNames

IF attachmentName ends with ".pdf" OR ".xlsx" THEN
mark as SAFE
ELSE
skip OR log as BLOCKED
END IF

END FOR

In Automation Anywhere this becomes:

  • Loop (For Each attachment)
  • If condition using string functions:
    • ends with
    • contains
    • regex if needed

Step 3: Download Only Approved Attachments

Only inside the “TRUE” condition:

  • Use Download Attachment
  • Pass:
    • Email ID
    • Attachment Name

Uzumaki
Forum|alt.badge.img+2
  • Author
  • Navigator | Tier 3
  • May 27, 2026

 ​@Uzumaki 

 

Step 1: Use “Get Email / List Emails” 

Depending on your package (Outlook / IMAP / Gmail connector):

You should first retrieve emails with:

  • Subject
  • Sender
  • Email ID
  • Attachment names 

Most AA email actions return something like:

  • AttachmentNames → array/list of file names
  • AttachmentCount

 

Attachments:
- invoice.pdf
- malware.exe
- report.xlsx

Step 2: Filter in Bot BEFORE Download

Use a loop + condition:

FOR each attachmentName in AttachmentNames

IF attachmentName ends with ".pdf" OR ".xlsx" THEN
mark as SAFE
ELSE
skip OR log as BLOCKED
END IF

END FOR

In Automation Anywhere this becomes:

  • Loop (For Each attachment)
  • If condition using string functions:
    • ends with
    • contains
    • regex if needed

Step 3: Download Only Approved Attachments

Only inside the “TRUE” condition:

  • Use Download Attachment
  • Pass:
    • Email ID
    • Attachment Name

The issue is that it looks like there is no supported way to view the attachment name or extension using either the email or outlook packages.

Using outlook it provides the option to save an email’s attachments to a list of file variables. Seems like it would make sense that I could then view the filenames from that list. But no, when trying to print the file path’s I get an error saying “Unable to get the file path when value is created using file stream connection”. 

The logic you posted makes sense, the issue is viewing the attachment names in the first place before downloading them.


Uzumaki
Forum|alt.badge.img+2
  • Author
  • Navigator | Tier 3
  • Answer
  • May 27, 2026

For anyone curious, I decided that the graph API is the best solution for this. The same client ID/secret used to connect to the O365 outlook package had graph access and that allows me to view attachment names before downloading.