We fine-tuned an email classification model so you can auto-label your emails locally with n8n.
We built a fully local Gmail auto-labeler with n8n + a fine-tuned 0.6B model (no email content sent to cloud LLMs)
Most of our inboxes are a mix of useful and distracting. Labels can help making order from the chaos - but labelling all emails manually takes time too.
We put together a setup that auto-labels Gmail locally, so email content does not go to external LLM APIs.
What it does (end-to-end local):
n8n trigger when you receive an email
It sends the email text (subject + snippet/body) to a fine-tuned model running on localhost via Ollama
It applies the predicted label back in Gmail (we recommend prefixing labels with AI/)
Label set (10-way closed set):
Billing, Newsletter, Work, Personal, Promotional, Security, Shipping, Travel, Spam, Other
1#install huggingface CLI if not instlalled 2python3 -m pip install -U huggingface_hub
34#download the model5hf download distil-labs/distil-email-classifier --local-dir ./distil-email-classifier
Run the model
bash
1#install Ollama or you can download from https://ollama.com/download2brew install ollama
34#start Ollama5ollama serve
67#navigate to your model folder8cd ./distil-email-classifier
910#create model in ollama 11ollama create email-classifier -f Modelfile
1213#verify the model is created or not 14ollama list
1516#run the model17ollama run email-classifier "test"1819#check the model is running or not20ollama ps2122Expected output:
2324NAME ID SIZE PROCESSOR CONTEXT UNTIL
25email-classifier:latest 695190b0f07f 3.5 GB 100% GPU 40964 minutes from now
2627#to keep model running forver run the below commands28OLLAMA_KEEP_ALIVE=-1 ollama run email-classifier "test"2930Now shows Forever instead of 4 minutes from now.
Once you finish the setup, open n8n in your browser (http://localhost:5678), sign up with your email, and you get an access code from n8n for your email, you can update the access code.
Real-time Classification: Triggers automatically on each incoming email
Batch Processing: Classifies multiple existing emails at once
To connect your Gmail you need to setup Gmail OAuth (Google cloud console) you can find detailed steps on this on github readme.
Before running the workflow, create all 10 labels manually in your Gmail account. Use the "AI/" prefix to match the model output (AI/Billing, AI/Work, AI/Travel, and so on).
Once this is running, New messages get labeled automatically.
If you want different labels, you can distill a custom version of this classifier on the distil labs platform. When you sign up, you get two free training credits to train the model.