Filtering Email Attachments by Type, Name, and Size
Use the Attachment node's filters to pick exactly the right file out of an inbound Mailhook email, whether you want a single PDF, every CSV, or one file by its exact ID.
Overview
When a Mailhook trigger receives an email, each attachment arrives as a lightweight reference (id, filename, and contentType) rather than as actual file data. The Attachment node fetches the real bytes, and its filter fields let you decide which of those references to fetch. This matters because real inbound mail is messy: vendor notifications carry signature logos, tracking pixels, and footer images alongside the one invoice PDF you actually care about. Filtering lets you target the right file without writing code, so the rest of your workflow always receives the file you expect.
Think of the filters as a funnel. Content type, Filename pattern, and Min/Max size narrow the set of candidate attachments; Attachment ID is an exact override that ignores the other filters; Mode decides whether you keep the first match or all matches; and Fail if no attachment matches controls what happens when nothing survives the funnel. This article is a reference for those filter fields specifically. For the node end to end, including its output shape and how it feeds downstream nodes, see the general Attachment node guide.
Before You Start
- Your workflow must use a Mailhook trigger. The Spojit designer refuses to save an Attachment node in any workflow that is not triggered by a Mailhook, because the node reads the attachment references that only a Mailhook trigger produces.
- Add an Attachment node to the canvas downstream of the trigger, then open its properties panel to set the filter fields described below.
Content Type Filter
The Content type field matches against each attachment's MIME type. Enter one or more values separated by commas, and use a wildcard for whole families. For example, application/pdf keeps only PDFs, image/* keeps any image (PNG, JPEG, GIF), and application/pdf, text/csv keeps both PDFs and CSV files. An attachment is kept only if its contentType matches one of the entries you list. This is the most reliable first filter because it ignores filenames, which senders often get wrong or leave blank.
Filename Pattern Filter
The Filename pattern field matches against each attachment's filename using glob syntax. Use * as a wildcard for any run of characters. For example, *.pdf keeps any file ending in .pdf, invoice-*.csv keeps files like invoice-2024.csv and invoice-march.csv, and *statement* keeps any file with the word statement anywhere in its name. Filename matching is handy when a sender attaches several files of the same content type and the name is the only thing that distinguishes the one you want.
Attachment ID (Exact Match)
The Attachment ID field selects one specific attachment by the id from its reference. When set, it ignores Content type, Filename pattern, and Min/Max size entirely and fetches exactly that one attachment. Reach for this when an earlier step in the run has already identified a specific attachment, for example after a Transform or Condition node inspects {{ input.attachments }} and decides which id to pull. You can template the field, such as {{ chosen.id }}, so the ID is resolved at run time rather than hard coded.
Min and Max Size Filters
The Min size and Max size fields filter by the byte size of each attachment. Use Min size to skip tiny tracking pixels and signature logos that would otherwise slip through a broad image/* content type filter, and use Max size to reject oversized files before they consume your run budget. Keep the platform limits in mind: by default each attachment can be up to 10 MB and a single run can fetch up to 25 MB across all attachments. Size filters pair well with content type filters when a vendor mixes inline graphics with a real document.
Mode: Single vs Multiple
The Mode field decides how many matches you keep after filtering. In Single mode, the node returns the first matching attachment as one object shaped { filename, contentType, size, content }, where content is the base64 file data. In Multiple mode, the node returns every match as { attachments: [...], count, totalBytes }. Choose Single when you expect exactly one file (one invoice per email) and Multiple when a sender batches several files you all need to process. In Multiple mode, add a Loop node and iterate over {{ attachment.attachments }} to handle each file in turn.
Fail if No Attachment Matches
The Fail if no attachment matches toggle is off by default. When it is off and no attachment survives the filters, the node returns an empty result and the workflow continues, which is the right choice when the file is optional. When you turn it on, a run with no matching attachment stops with an error instead of quietly producing nothing downstream. Turn it on whenever a missing file means the rest of the workflow cannot do its job, such as an invoice processing flow that has nothing to process without the PDF.
Tips
- Combine filters from broad to narrow: start with
Content type(e.g.application/pdf), then addFilename patternonly if multiple PDFs arrive together. - Add a small
Min size(for example, a few kilobytes) when you filter onimage/*to drop one pixel tracking images and email signature logos. - Let Miraxa, the intelligent layer across your automation, scaffold the node for you with a prompt like "Add an Attachment node that fetches the first PDF from the Mailhook email," then fine tune the filter fields in the properties panel.
- If you do not yet know an attachment's ID, inspect
{{ input.attachments }}from the Mailhook trigger output in a test run to see each reference'sid,filename, andcontentType.
Common Pitfalls
- Setting
Attachment IDsilently disables your other filters. If a file you expected is not being filtered out, check whether an ID is filling that field. - Filename filters fail when senders attach unnamed or oddly named files; prefer
Content typeas the primary filter and treatFilename patternas a tiebreaker. - With
Fail if no attachment matchesleft off, a too strict filter produces an empty result and downstream nodes receive nothing, which can look like a different bug. Turn the toggle on while testing to surface the mismatch immediately. - In Single mode the node keeps only the first match, so an overly broad filter may grab the wrong file when several qualify. Tighten the filter or switch to Multiple mode and loop.
Related Articles
- Setting Up a Mailhook Trigger
- Filtering Mailhook Emails
- Using Loop Nodes
- Using Knowledge Nodes
- Using Send Email Nodes