File emailed PDFs into the right Box folder
Reads each PDF that arrives by email and files it into the right Box folder by what it says, or leaves it for you when unsure.
What it does
Each integration step this workflow runs, in order, what it is for, and the conditions and loops that decide when it runs.
- 1
GmailNew email triggerWakes the workflow when a new email arrives in Gmail, so documents are sorted soon after they land. - 2
GmailList emailsLists up to 25 inbox emails matching your search that have attachments and carry neither the 'Document filing' nor the 'Needs sorting' label. For each
messageTry
- 3
GmailFind emailFinds the sender's newest inbox message to confirm this is the one whose attachments Gmail can hand over. - 4
GmailDownload attachmentsDownloads the attachments from the sender's newest message, of which only PDF files are treated as documents. - 5
GmailAdd label to messageMarks each email 'Document filing' before anything is copied, and adds 'Needs sorting' when a document cannot be placed or the email cannot be opened. For each
attachmentIf
documentDetailsis not empty- 6
OpenAIQuery modelAsks the AI to pick exactly one of your folder names from what the document says, or answer UNCLEAR rather than guess.
- 6
If
chosenFolderis not emptyTry
- 7
BoxUpload fileUploads the PDF to the chosen Box folder under its own name plus a reference to its email, so a name used before never clashes.
If a step fails
- 8
BoxList folder itemsOnly when an upload is refused: looks for a copy of this same document already in that folder, and counts it as filed instead of failing.
- 7
- 9
GmailAdd label to message
If a step fails
- 10
GmailAdd label to message
- 3
How it works
What happens on each run, in plain English.
Mail gets filed by who sent it, so the contract from your accountant ends up in the accounts folder. This reads each PDF that arrives by email for what kind of document it is, what it concerns, its reference, its date and any total, and an AI picks one of the Box folders you have described from those answers alone. The sender and subject are never shown to it, so an invoice is filed as an invoice whoever sent it. Each copy keeps its name plus a reference to its email, so a second Invoice.pdf never clashes with the first.
When the answer is not exactly one of your folders, or nothing could be read, nothing is copied and the email is labelled 'Needs sorting', a short queue you work through by hand. So is an older email Gmail cannot open because the same sender's newer one is still in the inbox. The run's last message lists each one. If reading, choosing or copying fails, the email is labelled the same way and the run ends as failed, saying what went wrong.
You need Gmail, Box and OpenAI connected, and up to three folders described in advance: a name, its Box folder and a line saying what belongs there. The Gmail search starts as any email from the past week with a PDF attached.
Start from a workflow that already works.
Add "File emailed PDFs into the right Box folder" to your workspace, connect its apps, and make it yours.
Free plan, no credit card