n8n

How to Automate Gmail Spam Cleanup Alerts?

Keep your Gmail inbox clean without constant manual sorting. The flow reviews older messages, removes marketing and spam, and sends you quick updates in Telegram. It suits busy teams and solo users who get too much promo mail and want less noise.

It runs on demand from n8n. Emails are pulled from Gmail in 14 day chunks using a smart date filter, so large inboxes are handled in manageable windows. Google Gemini scores each email with decimal confidence for unwanted, marketing, and spam, and returns a short reason plus the email ID and sender. If the scores signal unwanted content, the message is deleted and a Telegram alert shows the sender and reason. If it looks safe, a keep label is added in Gmail and you receive a skip notice. AI errors are also posted to Telegram, so you always know what happened.

You need Gmail access, a Telegram bot, and a Google Gemini API key. Set your Telegram chat ID and tune the confidence thresholds to match your risk level. Expect weekly inbox cleanup time to drop from hours to minutes while staying in control through clear alerts. You can add a schedule later with a Cron trigger to run this clean up daily.

What are the key features?

  • Gmail email fetch with rolling 14 day date filters and full pagination via loop variables
  • Google Gemini evaluates each message and returns structured scores and reasons
  • Conditional logic deletes unwanted emails based on marketing or spam confidence
  • Label safe emails in Gmail so they remain easy to find and review later
  • Telegram messages confirm deletes, skips, and AI errors with sender and brief reason
  • Built in error path to avoid silent failures and keep visibility high
  • Aggregate and loop control to process older periods step by step

What are the benefits?

  • Reduce manual inbox cleanup from hours each week to minutes with AI scoring and one tap execution
  • Automate up to 80 percent of promo and spam triage using confidence based deletion
  • Improve focus by removing low value emails before they reach your attention
  • Handle large inboxes by processing messages in 14 day windows without timeouts
  • Stay informed with clear Telegram alerts for deleted, skipped, and error cases

How do you set it up?

  1. Import the template into n8n: Create a new workflow in n8n > Click the three dots menu > Select 'Import from File' > Choose the downloaded JSON file.
  2. You'll need accounts with Gmail, Google Gemini and Telegram. See the Tools Required section above for links to create accounts with these services.
  3. Open the Gmail nodes and connect credentials: double click each Gmail node, then on the 'Credential to connect with' dropdown click 'Create new credential', choose Gmail OAuth2, and follow the on screen steps to sign in with your Google account.
  4. Set up the Telegram credentials: double click each Telegram node, click 'Create new credential', paste your bot token from BotFather, and save. Update the chatId field with your own Telegram chat ID.
  5. Connect Google Gemini: double click the Google Gemini Chat Model node, click 'Create new credential', and add your API key from the Google AI Studio or PaLM API page. Save the credential.
  6. Review the Gmail Get Email node query. It already uses a 14 day before and after filter tied to the loop page variable. You can keep it as is or adjust the date window to fit your mailbox size.
  7. Open the AI Check Email node and confirm the prompt asks for decimal confidence scores and includes emailId and emailFrom. Keep the linked structured output parser so fields map correctly.
  8. Adjust the If Unwanted Marketing or Spam node to match your threshold. For example, treat isMarketingConfidence or isSpamConfidence above 0.7 as unwanted.
  9. Confirm the GmailDeleteEmail and Gmail modify nodes both use messageId set to the parsed emailId field. In the Gmail modify node, pick or create a label you want for kept emails.
  10. Click Execute Workflow to test. Watch Telegram for delete or skip alerts. Check your Gmail Trash and labels to confirm the actions match the alerts.
  11. If no Telegram alerts arrive, verify the bot token and chatId. If AI errors appear, check your Google Gemini API key and quota. If labels fail, open the Gmail node and select a valid label.
  12. Optional: add a Cron node to run daily or weekly, then connect it to replace the manual trigger for hands free cleanup.

Tools Required

$24 / mo or $20 / mo billed annually to use n8n in the cloud. However, the local or self-hosted n8n Community Edition is free.

Gmail

Sign up

No cost: Personal Gmail (Gmail API has no usage-based pricing; quotas apply)

Google Gemini

Sign up

Free tier: $0 via Gemini API; e.g., Gemini 2.5 Flash-Lite free limits 1,000 requests/day (15 RPM, 250k TPM). Paid from $0.10/1M input tokens and $0.40/1M output tokens.

Telegram

Sign up

Free: $0, Telegram Bot API usage is free for developers

Similar Templates

Join Futurise to access 1,200+ automation templates

Get instant access to ready-made automation workflows for n8n, Make.com, AI agents, and more. Download, customise, and deploy in minutes.