luffyDTaro/Gmail_Notifications
๐ GMAIL Alert Bot
Smart Gmail โ Telegram notification system for GMAIL alerts.
Monitors your Gmail for GMAIL -related emails and sends real-time notifications to your Telegram โ 100% FREE. Includes a premium web dashboard for live configuration.
โจ Features
- ๏ฟฝ Web Dashboard: Configure everything from a beautiful dark-theme UI
- ๏ฟฝ๐ Two Alert Modes:
all(every email) orfiltered(smart filtering) - โ Whitelist: Only alert for specific senders or keywords
- ๐ซ Blacklist: Auto-skip spam, promos, irrelevant emails (overrides whitelist)
- ๐ท Safe Processing: Uses
PROCESSED_BY_BOTlabel โ no emails lost, no mark-as-read - ๐ Retry Logic: Exponential backoff if Telegram fails
- ๐พ Hot-Reload: Change settings from dashboard โ no restart needed
- ๐ Live Stats: Track checks, alerts, skipped emails in real-time
- โ Free Deployment: Ready for Hugging Face Spaces
๐ Setup Guide (Step-by-Step)
Step 1: Install Dependencies
cd GMAIL -alert-bot
npm installStep 2: Create Telegram Bot & Get Chat ID
2a. Create the Bot
- Open Telegram โ search for @BotFather
- Send
/startthen/newbot - Choose a name and username
- Copy the Bot Token (looks like
123456:ABC-DEF...)
2b. Get Your Chat ID
- Open Telegram โ send any message (like "hi") to your new bot
- Open this URL in browser (replace
<TOKEN>with your bot token):
https://api.telegram.org/bot<TOKEN>/getUpdates- Look for
"chat": { "id": 123456789 }โ that number is your Chat ID
Step 3: Configure Environment
- Copy the example env file:
copy .env.example .env- Edit
.envโ you only need to fill in two values to get started:
TELEGRAM_BOT_TOKEN=your_actual_bot_token
TELEGRAM_CHAT_ID=your_actual_chat_id- Everything else (alert mode, whitelist, blacklist, etc.) can be configured later from the web dashboard.
Step 4: Set Up Gmail API (Free)
4a. Create Google Cloud Project
- Go to Google Cloud Console
- Click "Select a project" โ "New Project"
- Name it (e.g., "GMAIL Alert Bot") โ Create
4b. Enable Gmail API
- Go to APIs & Services โ Library
- Search for "Gmail API"
- Click it โ Enable
4c. Configure OAuth Consent Screen
- Go to APIs & Services โ OAuth consent screen
- Select External โ Create
- Fill in:
- App name:
GMAIL Alert Bot - User support email: your email
- Developer email: your email
- Click Save and Continue through all steps
- Go to Test users โ Add Users โ add your Gmail address
4d. Create OAuth Credentials
- Go to APIs & Services โ Credentials
- Click Create Credentials โ OAuth client ID
- Application type: Desktop app
- Name: anything (e.g., "Alert Bot")
- Click Create
- Click Download JSON
- Rename the downloaded file to
credentials.json - Place it in the project root (same folder as
package.json)
Step 5: Create Gmail Filter (Optional but Recommended)
In Gmail:
- Click the search bar โ Click the filter icon โ Create filter
- Set rules like:
- From:
GMAILORhr - Subject:
interviewORtestORassignment - Click Create filter โ Check Apply label โ Create label
GMAIL _ALERT - Also check Also apply to matching conversations
Step 6: Run Setup Wizard
npm run setupThis will:
- โ
Verify your
.envconfiguration - โ Test Telegram bot connection
- โ Guide you through Gmail OAuth (opens browser)
- โ Save your auth token
Step 7: Start the Bot
npm startYou'll see:
๐ GMAIL Alert Bot โ Starting...
โ
Gmail authenticated!
๐ PROCESSED_BY_BOT label ready
๐ฑ Startup notification sent to Telegram!
๐ Dashboard: http://localhost:7860
๐ข Bot is running.Open http://localhost:7860 in your browser to access the configuration dashboard!
๐ Web Dashboard
The dashboard lets you configure everything from your browser โ no need to edit .env manually:
Changes are saved to .env and applied instantly โ no restart needed.
๐ Configuration Reference
Filtering Logic
1. Fetch unread emails (not yet processed by bot)
2. For each email:
โ If sender in BLACKLIST โ SKIP
โ If subject has BLACKLIST keyword โ SKIP
โ If ALERT_MODE = "all" โ SEND
โ If ALERT_MODE = "filtered":
โ If sender in WHITELIST โ SEND
โ If subject has WHITELIST keyword โ SEND
โ Otherwise โ SKIP
3. On successful Telegram send โ Add PROCESSED_BY_BOT label
4. Failed sends โ email stays unprocessed, retried next cycleโ Deploy on Hugging Face Spaces (Free, 24/7)
What Goes Where
Since the dashboard handles most configuration, you only need 3 things as Hugging Face Space Secrets:
โ ๏ธ Note: Dashboard changes are saved to .env in the container, but are lost on container restart. For persistent settings, set them as Hugging Face Space Secrets.Deployment Steps
- Create a new Space at huggingface.co/spaces
- Select Docker as the SDK
- Upload all project files (except
.env,credentials.json,token.json) - Add required secrets in Space Settings โ Secrets:
TELEGRAM_BOT_TOKEN= your bot tokenTELEGRAM_CHAT_ID= your chat ID- Encode `credentials.json` and `token.json` as base64:
On your PC, run these commands to get the base64 strings:
# PowerShell
[Convert]::ToBase64String([IO.File]::ReadAllBytes("credentials.json"))
[Convert]::ToBase64String([IO.File]::ReadAllBytes("token.json"))Add these as Space Secrets:
GOOGLE_CREDENTIALS= base64 output of credentials.jsonGOOGLE_TOKEN= base64 output of token.json
- Update `Dockerfile` entry point to decode secrets at startup (see below)
- Space builds and deploys automatically โ your bot runs 24/7!
Updated Dockerfile (for base64 secrets)
The included Dockerfile already handles this. On startup, if GOOGLE_CREDENTIALS and GOOGLE_TOKEN environment variables exist, the app will decode them into files.
๐ Project Structure
GMAIL -alert-bot/
โโโ package.json
โโโ .env.example # Environment template
โโโ .env # Your actual config (git-ignored)
โโโ .gitignore
โโโ credentials.json # Gmail OAuth creds (git-ignored)
โโโ token.json # Saved auth token (git-ignored)
โโโ setup.js # Interactive setup wizard
โโโ Dockerfile # For Hugging Face deployment
โโโ README.md
โโโ public/
โ โโโ dashboard.html # Web dashboard UI
โโโ src/
โโโ index.js # Main entry point + scheduler
โโโ config.js # Config loader + validator
โโโ auth.js # Gmail OAuth2 authentication
โโโ gmail.js # Email fetching + filtering
โโโ telegram.js # Telegram notifications
โโโ dashboard.js # Dashboard API routes๐ฏ Resume-Worthy Description
Smart GMAIL Alert System Built a real-time email monitoring system using Node.js, Gmail API (OAuth2), and Telegram Bot API. Features a premium web dashboard for live configuration, dual alert modes with whitelist/blacklist filtering, safe-processing with custom Gmail labels, retry logic with exponential backoff, and containerized cloud deployment on Hugging Face Spaces.
