gmail-to-exchange365
v1.1.0
Published
Complete Gmail to Exchange 365 migration tool with UI - Migrate emails, attachments, and folders seamlessly
Maintainers
Readme
📧 Gmail → Exchange 365 Migrator
A complete, production-ready application for migrating emails, attachments, and folders from Gmail to Microsoft Exchange 365 (Office 365).
✨ Features
- ✅ Full Email Migration: Migrates emails with all metadata (from, to, cc, bcc, subject, date)
- ✅ Attachment Support: Preserves all email attachments
- ✅ Folder/Label Mapping: Automatically maps Gmail labels to Exchange folders
- ✅ OAuth Authentication: Secure OAuth 2.0 login for both Google and Microsoft
- ✅ Progress Tracking: Real-time progress bar and detailed logs
- ✅ Batch Processing: Configurable batch sizes to handle large migrations
- ✅ Rate Limiting: Built-in delays to respect API rate limits
- ✅ Error Handling: Automatic retry with exponential backoff
- ✅ Pause/Resume: Control migration flow with pause and resume
- ✅ Modern UI: Beautiful, responsive web interface
- ✅ Electron Support: Optional desktop app wrapper
- ✅ TypeScript: Fully typed codebase for maintainability
🚀 Quick Start
Option 1: Run with npx (Easiest - No Installation)
npx gmail-to-exchange365This will:
- Automatically create a
.envtemplate file - Guide you through setup
- Start the migration server
Option 2: Install Globally
npm install -g gmail-to-exchange365
gmail-to-exchange365Option 3: Install Locally
npm install gmail-to-exchange365
npx gmail-to-exchange365Prerequisites
- Node.js 20+ installed
- Google Cloud Project with Gmail API enabled
- Microsoft Azure App Registration with Mail API permissions
First-Time Setup
When you run the tool for the first time, it will create a .env file template. You need to:
Get Google OAuth Credentials (see SETUP.md for details)
- Go to Google Cloud Console
- Enable Gmail API
- Create OAuth 2.0 credentials
- Add redirect URI:
http://localhost:3000/google/callback
Get Microsoft OAuth Credentials (see SETUP.md for details)
- Go to Azure Portal
- Create App Registration
- Add API permissions:
Mail.Read,Mail.ReadWrite,MailboxSettings.ReadWrite - Add redirect URI:
http://localhost:3000/ms/callback
Edit the
.envfile with your credentials:
# Google OAuth Credentials
GOOGLE_CLIENT_ID=your_google_client_id_here
GOOGLE_CLIENT_SECRET=your_google_client_secret_here
GOOGLE_REDIRECT=http://localhost:3000/google/callback
# Microsoft OAuth Credentials
MS_CLIENT_ID=your_ms_client_id_here
MS_CLIENT_SECRET=your_ms_client_secret_here
MS_TENANT_ID=common
MS_REDIRECT=http://localhost:3000/ms/callback
# Session Configuration
SESSION_SECRET=your_random_session_secret_here
# Server Configuration
PORT=3000Setting up OAuth Credentials
Google OAuth Setup
- Go to Google Cloud Console
- Create a new project or select an existing one
- Enable the Gmail API
- Go to Credentials → Create Credentials → OAuth 2.0 Client ID
- Set application type to Web application
- Add authorized redirect URI:
http://localhost:3000/google/callback - Copy the Client ID and Client Secret to your
.envfile
Microsoft OAuth Setup
- Go to Azure Portal
- Navigate to Azure Active Directory → App registrations
- Click New registration
- Set redirect URI:
http://localhost:3000/ms/callback - Go to API permissions → Add:
Mail.ReadMail.ReadWriteMailboxSettings.ReadWriteoffline_access
- Go to Certificates & secrets → Create a new client secret
- Copy the Application (client) ID and Client secret to your
.envfile
🎯 Usage
Simple Usage
Just run:
npx gmail-to-exchange365Or if installed globally:
gmail-to-exchange365The tool will:
- ✅ Check/create
.envfile automatically - ✅ Validate your OAuth credentials
- ✅ Start the web server
- ✅ Open
http://localhost:3000in your browser
Web Interface
The server starts automatically when you run the command above
Open your browser
Navigate to http://localhost:3000 (or the URL shown in the terminal)
Connect accounts
- Click Connect Google and authorize the app
- Click Connect Microsoft and authorize the app
Configure migration
- Set batch size (default: 10 emails per batch)
- Set delay between batches (default: 1000ms)
Start migration
- Click Start Migration
- Monitor progress in real-time
- Use Pause, Resume, or Stop as needed
Electron Desktop App
# In one terminal, start the server
npm start
# In another terminal, start Electron
npm run electronOr use the combined command:
npm run electron:dev📁 Project Structure
gmail-to-exchange365/
├── src/
│ ├── index.ts # Application entry point
│ ├── server/
│ │ ├── app.ts # Express app configuration
│ │ ├── routes.ts # API routes
│ │ ├── types.ts # TypeScript type definitions
│ │ ├── googleAuth.ts # Google OAuth handling
│ │ ├── msAuth.ts # Microsoft OAuth handling
│ │ ├── gmailFetcher.ts # Gmail API integration
│ │ ├── exchangePusher.ts # Exchange API integration
│ │ ├── folderMapper.ts # Folder/label mapping
│ │ └── migrator.ts # Migration coordinator
│ └── ui/
│ ├── index.html # Main UI
│ ├── app.js # Frontend JavaScript
│ └── styles.css # Styling
├── electron/
│ └── main.js # Electron main process
├── package.json
├── tsconfig.json
└── README.md🔧 Configuration Options
Migration Options
You can configure migration behavior via the UI or by modifying the API call:
- batchSize: Number of emails to process per batch (default: 10)
- delayBetweenBatches: Delay in milliseconds between batches (default: 1000)
- retryAttempts: Number of retry attempts for failed emails (default: 3)
- retryDelay: Delay in milliseconds before retry (default: 5000)
🛠️ Development
Development Mode
npm run devThis runs the server with auto-reload on file changes.
Building
npm run buildCompiles TypeScript to JavaScript in the dist/ directory.
📝 API Endpoints
GET /- Main UIGET /google/auth- Initiate Google OAuthGET /google/callback- Google OAuth callbackGET /ms/auth- Initiate Microsoft OAuthGET /ms/callback- Microsoft OAuth callbackGET /api/status- Check authentication statusPOST /api/migrate- Start migration (returns Server-Sent Events)POST /api/migrate/pause- Pause migrationPOST /api/migrate/resume- Resume migrationPOST /api/migrate/stop- Stop migrationPOST /api/logout- Clear session
⚠️ Important Notes
Rate Limits: Both Gmail and Microsoft Graph APIs have rate limits. The app includes built-in delays, but for very large migrations, you may need to increase delays.
Large Migrations: For accounts with thousands of emails, the migration may take several hours. The app supports pause/resume functionality.
Session Storage: Sessions are stored in the
sessions/directory. Make sure this directory is writable.Security: In production, use HTTPS and secure session storage. Never commit your
.envfile.Permissions: Ensure your OAuth apps have the correct scopes:
- Google:
gmail.readonly,gmail.labels - Microsoft:
Mail.Read,Mail.ReadWrite,MailboxSettings.ReadWrite
- Google:
🐛 Troubleshooting
"Missing required environment variables"
Make sure your .env file exists and contains all required variables. See .env.example for reference.
"OAuth error" or "Authentication failed"
- Verify your OAuth credentials are correct
- Check that redirect URIs match exactly (including
http://vshttps://) - Ensure APIs are enabled in your cloud consoles
"Rate limit exceeded"
- Increase the
delayBetweenBatchesvalue - Reduce the
batchSize - Wait and retry later
Migration stops or fails
- Check the logs in the UI
- Verify both accounts are still connected
- Check network connectivity
- Review API quotas in Google Cloud Console and Azure Portal
📄 License
MIT License - feel free to use this project for your email migrations.
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
📧 Support
For issues, questions, or feature requests, please open an issue on the repository.
Happy Migrating! 🚀
