All workflows
Gmail logoOpenAI logoBox logo

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.

On new email in Gmail3 apps10 steps

Apps it connects

Authenticate each one once and the workflow is ready to run.

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. 1GmailNew email triggerWakes the workflow when a new email arrives in Gmail, so documents are sorted soon after they land.
  2. 2GmailList emailsLists up to 25 inbox emails matching your search that have attachments and carry neither the 'Document filing' nor the 'Needs sorting' label.
  3. For each message

    1. Try

      1. 3GmailFind emailFinds the sender's newest inbox message to confirm this is the one whose attachments Gmail can hand over.
      2. 4GmailDownload attachmentsDownloads the attachments from the sender's newest message, of which only PDF files are treated as documents.
      3. 5GmailAdd 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.
      4. For each attachment

        1. If documentDetails is not empty

          1. 6OpenAIQuery modelAsks the AI to pick exactly one of your folder names from what the document says, or answer UNCLEAR rather than guess.
        2. If chosenFolder is not empty

          1. Try

            1. 7BoxUpload 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

            1. 8BoxList 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.
        3. 9GmailAdd label to message

      If a step fails

      1. 10GmailAdd label to message

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.

gmailboxdocumentsattachmentsfilingclassification

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