This guide will walk you through setting up the "Automated Mail Bridge" for your repository. The process involves three main phases: Getting the Gmail Token, Configuring GitHub Secrets, and Enabling Actions.
To interact with the Gmail API, we first need to create a project in Google Cloud, generate a credentials.json file, and run a local script to generate the access Token.
If you already have a project, skip to 1.2.
- Go to the Google Cloud Console.
- Click the project selector at the top of the page and select "New Project".
- Name your project (e.g.,
Mail-Bridge) and click "Create".
- Ensure your newly created project is selected.
- In the left navigation menu, go to "APIs & Services".
- Type "Gmail API" into the search bar.
- Click on Gmail API in the results and click "Enable".
- Go to "APIs & Services" > "OAuth consent screen".
- For User Type, select "External" (for personal Gmail) or "Internal" (for Workspace orgs), then click "Create".
- Fill in the required fields:
- App name:
Mail Bridge - User support email: Your Gmail address.
- Developer contact info: Your Gmail address.
- App name:
- Click "Save and Continue". On the Scopes page, simply click "Save and Continue" again.
- IMPORTANT (If you chose External): Under the "Test users" section, click "Add Users" and type in your own Gmail address.
- Go to "APIs & Services" > "Credentials".
- Click "+ Create Credentials" at the top and select "OAuth client ID".
- For Application type, choose "Desktop App".
- Set any Name (e.g.,
My Python Script) and click "Create". - A modal saying "OAuth client created" will appear. Click "Download JSON".
- Rename the file: Rename the downloaded file (which has a very long name) exactly to
credentials.json.
- Place
credentials.jsonin thesrc/directory of this repository (same folder asgen_token.py). - Open your local terminal and install the dependencies first:
pip install -r requirements.txt - Run the generation script:
python src/gen_token.py - Your web browser will open automatically. Make sure to check all permission boxes (especially "Read your email", which is required for the Threading feature to work).
- Once authenticated, a
token.jsonfile will be generated in your directory. Keep this safe and NEVER commit it to a public repository!
Next, we need to securely store your credentials in GitHub.
Navigate to your GitHub repository, go to Settings -> Secrets and variables -> Actions, and click New repository secret.
Create a new secret:
- Name:
GMAIL_TOKEN_JSON - Secret: Open the
token.jsonyou generated in Part 1 with a text editor, copy its entire content, and paste it here.
Create another secret named ACCOUNTS_JSON. This dictates which third-party accounts will be fetched. Format it strictly as a JSON array as shown below:
[
{
"name": "Tencent_Exmail",
"imap_server": "imap.exmail.qq.com",
"imap_port": 993,
"email": "username@example_tencent.email",
"password": "YOUR_TENCENT_PASSWORD"
},
{
"name": "Aliyun_Exmail",
"imap_server": "imap.qiye.aliyun.com",
"imap_port": 993,
"email": "username@example_ali.com",
"password": "YOUR_ALIYUN_PASSWORD"
}
]
Note: The
passwordhere is usually an "App Password / Authorization Code" generated by your third-party email provider, not your actual web login password.
- Make sure
.github/workflows/mail_bridge.ymlis pushed to your default branch (mainormaster). - Click the Actions tab at the top of your GitHub repository.
- Select IMAP to Gmail Bridge from the left sidebar.
- Click the Run workflow button on the right to trigger a manual test.
- Expand the logs. If you see
[+] Successfully inserted message to Gmail, congratulations! GitHub will now fetch your emails automatically every 30 minutes.