Ask Steves · Daily notes · VPS, 20% off · AI Profit Lab · SEO · Money Hub

1 November 2026 · Practical AI builds

How do I sort incoming emails into categories with AI?

By the end of this you will have a small script that checks your inbox every few minutes. It reads each new email and files it under a label or folder such as Enquiry, Invoice or Noise before you open it. It suits anyone who runs a small business or freelance work from one busy inbox and wants the important messages to stand out without setting up a full helpdesk.

I learn my automation tips in the AI Profit Boardroom. Have a look here. Affiliate link.

What you need

Step by step

  1. Write down your categories first and keep them few, for example Enquiry, Invoice, Receipt, Newsletter, Noise and Check. Four to seven works far better than twenty.
  2. Create a matching folder or label for each one in your email account, so the script has somewhere to put things.
  3. Set up ordinary inbox rules for the easy cases, such as invoices that always come from the same accounting address. Rules are free and never guess, so keep the AI for the messages they cannot catch.
  4. Turn on IMAP in your email settings and create an app password, so the script never holds your main password.
  5. Write a short instruction (the prompt) that lists the categories, says what each one means and asks for a fixed answer format:
    Sort this email into exactly one category.
    Enquiry: a person asking about work, prices or availability.
    Invoice: a bill or payment request sent to me.
    Receipt: confirmation of something already paid.
    Newsletter: mailing lists I signed up for.
    Noise: adverts, cold sales pitches, automated alerts.
    Check: anything that does not clearly fit.
    Reply with JSON only:
    {"category": "Enquiry", "confidence": "high"}
    
    From: {sender}
    Subject: {subject}
    Body: {first 300 words}
  6. Have the script connect over IMAP, fetch unread messages, and send only the sender, subject and opening few hundred words of each one to the model.
  7. Check that the reply names one of your exact categories. If it names anything else, or the confidence is low, file the email under Check.
  8. Move or label the email and leave it marked as unread, so you still see it as new.
  9. For the first week, run it in log-only mode. It writes what it would have done to a file and moves nothing. Compare that log with your own judgement.
  10. Once you trust it, schedule it, for example every ten minutes with cron:
    */10 * * * * /usr/bin/python3 /home/user/sort_mail.py >> /home/user/sort_mail.log 2>&1

What good looks like

You open your inbox and new messages are already sitting under the right labels, still unread. The log shows one line per email with the category it chose. The Check folder stays small, and when you look through it you mostly agree it was right to hold those back. If you keep moving the same kind of email by hand, reword that category's description in the prompt rather than adding a new category.

Watch out for

Privacy comes first. Every email you classify is sent to the AI provider, so read their data terms, tell clients if your privacy notice needs it, and leave out folders that hold medical, legal or financial details. A local model keeps everything on your own machine. Second, the AI will sometimes be wrong, and an email labelled Invoice is not proof that the invoice is genuine. Never let the script delete, pay, forward or reply to anything. It should only sort, and a person should make every decision that matters. There is more on this in how to keep AI replies from inventing facts.

Questions people ask

Can it read attachments such as PDF invoices?

It can if you extract the text first, but for sorting, the sender, subject and opening lines are usually enough. Sending less keeps it cheaper and shares less of your data.

Can it also put new enquiries somewhere I can track them?

Yes. Once an email is labelled Enquiry, the same script can add the sender and subject as a row in a spreadsheet, much like filing form enquiries into a spreadsheet automatically.

In short: a handful of clear categories, a strict prompt, a Check folder for anything uncertain and a scheduled script that only ever sorts. Together they give you an inbox that is labelled before you read it, while every real decision stays with you.

Want more automation tips? The AI Profit Boardroom on Skool is where I get mine. Have a look here. Affiliate link.

Related AI builds: How do I get AI to tag and name a folder of photos? · How do I connect a website form to an AI that drafts the first reply? · How do I pull the details out of invoices and receipts with AI? · All daily notes