This application monitors Gmail for new emails and sends notifications to Discord via webhooks. It uses OAuth 2.0 authentication and is designed for headless server deployment.
- Docker and Docker Compose installed
- Google Cloud Platform account
- Discord server with webhook permissions
- Gmail account (personal or Google Workspace)
- Local machine with browser (for initial OAuth setup)
Create a Google Cloud Project
- Go to Google Cloud Console
- Create a new project or select existing one
Enable Gmail API
- Navigate to "APIs & Services" > "Library"
- Search for "Gmail API"
- Click "Enable"
Create OAuth 2.0 Credentials
- Go to "APIs & Services" > "Credentials"
- Click "+ CREATE CREDENTIALS" > "OAuth client ID"
- Choose "Desktop application"
- Click "Create"
- Download the JSON file and rename it to
client_secret.json
Create Discord Webhook
- Go to your Discord server
- Right-click on the channel where you want notifications
- Select "Edit Channel" > "Integrations" > "Webhooks"
- Click "New Webhook"
- Copy the webhook URL
The OAuth token must be generated on a local machine with a browser before deploying to your server.
On your local machine:
- Download
generate_token.pyand place yourclient_secret.jsonin the same directory - Install Python dependencies:
pip install google-auth google-auth-oauthlib google-api-python-client
- Run the token generator:
python generate_token.py
- Follow the authentication flow in your browser
- Copy the generated
token.jsonto your server
Download docker-compose.yml
# Create project directory
mkdir GmailToDiscord
cd GmailToDiscord
# Download the docker-compose.yml file directly
wget https://raw.githubusercontent.com/Rockerkemm/GmailToDiscord/main/docker-compose.ymlConfigure the Docker Compose file:
Edit the docker-compose.yml file and update DISCORD_WEBHOOK_URL:
services:
gmail-webhook:
image: ghcr.io/rockerkemm/gmailtodiscord:latest
container_name: gmail-to-discord
restart: unless-stopped
volumes:
# Mount data folder and token.json
- ./data:/app/data
- ./token.json:/app/token.json
environment:
# Discord webhook URL - REPLACE WITH YOUR WEBHOOK URL
DISCORD_WEBHOOK_URL: "https://discord.com/api/webhooks/YOUR_WEBHOOK_URL_HERE"
# OAuth 2.0 configuration
TOKEN_FILE: "token.json"
stdin_open: true
tty: trueCopy token.json to the project directory:
scp token.json username@to_host:/pathToDirectory/The docker-compose.yml file is configured to automatically pull the latest Docker image from GitHub Container Registry.
Start the container:
docker-compose up -dCheck status:
docker-compose psView logs:
docker-compose logs -f gmail-webhookExpected output:
Starting Gmail to Discord webhook with OAuth 2.0...
Loaded existing OAuth credentials
OAuth 2.0 authentication successful
First time running! Will process the most recent email.
Starting continuous monitoring (checking every 10 seconds)
The application uses minimal required permissions:
https://www.googleapis.com/auth/gmail.readonly- Read-only access to Gmail
The application automatically filters out:
- Draft messages (
DRAFTlabel) - Scheduled messages (
SCHEDULEDlabel)
The application is distributed as a Docker image hosted on GitHub Container Registry:
- Latest stable:
ghcr.io/rockerkemm/gmailtodiscord:latest
The project includes generate_token.py for generating OAuth tokens. Run this script on a local machine with browser access before deploying to your server.