A command-line interface for accessing Gmail, built with Bun and the Gmail API. Efficiently manage and read your Gmail messages directly from the terminal.
# macOS or Linux
curl -fsSL https://bun.sh/install | bash
Clone the repository and install dependencies:
git clone https://github.com/EsmaeelNabil/gmail-cli
cd gmail-cli
bun install
- Go to the Google Cloud Console
- Create a new project or select an existing one
- Enable the Gmail API:
- Go to "APIs & Services" > "Library"
- Search for "Gmail API"
- Click "Enable"
- Set up credentials:
- Go to "APIs & Services" > "Credentials"
- Click "Create Credentials" > "OAuth client ID"
- Choose "Desktop app" as the application type
- Name your client
- Download the JSON file
- Save the downloaded JSON file as
credentials.json
in~/.config/gmail/
Your credentials file should look similar to this:
{
"installed": {
"client_id": "your-client-id.apps.googleusercontent.com",
"project_id": "your-project-id",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_type": "https://oauth2.googleapis.com/token",
"client_secret": "your-client-secret",
"redirect_uris": ["http://localhost"]
}
}
# Read latest 5 messages (default)
bun src/gmail.js
# Read specific number of messages
bun src/gmail.js -m 10
# Use custom credentials file location
bun src/gmail.js -c /path/to/credentials.json
# Enable debug logging
bun src/gmail.js --debug
Option | Alias | Description | Default |
---|---|---|---|
--count |
-m |
Number of messages to fetch | 5 |
--credentials |
-c |
Path to credentials file | ./credentials.json |
--debug |
Enable debug logging | false |
|
--help |
Show help | ||
--version |
Show version |
On first run, the application will:
- Open your default browser
- Ask you to login to your Google account
- Request permission to access your Gmail
- Save the authentication token locally in
token.json
Subsequent runs will use the saved token.
To build a standalone binary:
# Make the release script executable
chmod +x release.sh
# Build the binary
./release.sh gmail-client src/gmail.js
# The binary will be created in the current directory
./gmail-client
gmail-cli/
├── src/
│ ├── gmail.js # Main entry point
│ ├── cli.js # CLI argument handling
│ ├── services/ # Core services
│ ├── auth/ # Authentication handling
│ ├── config/ # Configuration management
│ └── utils/ # Utility functions
├── credentials.json # Gmail API credentials
├── token.json # Generated auth token
├── release.sh # Build script
└── package.json # Project dependencies
credentials.json
andtoken.json
contain sensitive information- Never commit these files to version control
- Keep these files secure on your local machine
- Added them to
.gitignore
If you experience authentication issues:
- Delete
token.json
- Run the application again
- Complete the authentication flow
Ensure your Google Cloud Project has:
- Gmail API enabled
- Valid OAuth 2.0 credentials
- Correct application type (Desktop)
Make sure:
- Bun is installed and in PATH
release.sh
is executable- You're on a supported platform (macOS/Linux)
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
For issues and feature requests, please open an issue on GitHub.