Table of Content
- Syncing Gmail to Notion - Complete Guide
- Phase 1: Notion API Setup
- 1. Create a Notion Integration (API Key)
- 2. Create the Notion Database
- 3. Share the Database with the Integration
- Phase 2: Google Apps Script Setup and Deployment
- 4. Create the Google Apps Script Project
- 5. Configure the Script Properties
- 6. Run and Authorize the Script
- 7. Set up the Time-Driven Trigger
Syncing Gmail to Notion - Complete Guide
This guide provides the complete, step-by-step process for connecting Gmail to Notion using Google Apps Script (GAS).
Phase 1: Notion API Setup
1. Create a Notion Integration (API Key)
- Go to the Notion Integrations Page.
- Click + New integration.
- Give it a name (e.g., "Gmail Sync").
- Associate it with the workspace you are using.
- Under "Content Capabilities," make sure Read content and Insert content are checked.
- Click Submit.
- IMPORTANT: On the next screen, copy the Internal Integration Token and save it securely. This is your
NOTION_API_KEY.
2. Create the Notion Database
- In your Notion workspace, create a new page and turn it into a Database (Table View).
- Name the database (e.g., "Email Inbox").
Property Name | Property Type | Notes |
Subject | Title | This will hold the Email Subject. (Default column) |
Date | Date | This will hold the received date. |
Link to Email | URL | This will hold the direct Gmail URL to the message. |
Sender | Text | The email address of the sender. |
Snippet | Text | A short preview of the email content. |
Status | Select | Ensure “Status” select option “📥 Inbox” |
3. Share the Database with the Integration
- Open the Notion Database page you just created.
- Click the ... (three dots) menu in the top right corner.
- Click Add connections at the bottom of the menu.
- Search for and select the integration you created in Step 1 (e.g., "Gmail Sync").
- IMPORTANT: Once the integration is connected, copy the Database ID from the URL. The URL format is
https://www.notion.so/{workspace_name}/{**DATABASE_ID**}?v=.... Copy the 32-character string that appears immediately after the workspace name. This is yourNOTION_DATABASE_ID.
Phase 2: Google Apps Script Setup and Deployment
4. Create the Google Apps Script Project
- Go to script.google.com and click + New project.
- Rename the project (e.g., "Gmail to Notion Sync").
- Replace the default
Code.gscontent with the script provided in the next file block.
5. Configure the Script Properties
The script uses script properties to securely store your Notion keys and settings.
- In the Apps Script editor, click the Settings icon (⚙) on the left sidebar.
- Scroll down to Script properties.
- Click + Add script property and enter the following three properties, using the values you copied from Notion:
- Click Save script properties.
Property Key | Property Value | Description |
NOTION_API_KEY | secret_... | Your 32-character Integration Token. |
NOTION_DATABASE_ID | a9b2c... | Your 32-character Database ID. |
GMAIL_SEARCH_QUERY | is:starred OR label:"Send to Notion" | The Gmail query to find emails. |
SYNC_LABEL_NAME | Notion Synced | The label the script will apply after syncing. |
6. Run and Authorize the Script
- Go back to the Editor icon (<>) on the left sidebar.
- Select the
syncEmailsToNotionfunction from the dropdown menu (it should be selected by default). - Click the Run button.
- The first time you run it, you must grant permissions:
- Click Review permissions.
- Select your Google Account.
- You will see a warning screen; click Advanced and then Go to “Project Name”
- Click Allow to grant access to Gmail, external connection services (
UrlFetchApp), and configuration (PropertiesService).
‣
(unsafe).
7. Set up the Time-Driven Trigger
This step ensures the script runs automatically (e.g., every 15 minutes).
- In the Apps Script editor, click the Triggers icon (⏰) on the left sidebar.
- Click + Add Trigger in the bottom right.
- Set the following options:
- Choose which function to run:
syncEmailsToNotion - Choose deployment to run:
Head - Select event source:
Time-driven - Select type of time-based trigger:
Hour timer(orMinutes timer) - Select hour of day/interval:
Every 15 minutes(Recommended) - Click Save.
The setup is complete! The script will now run on the schedule you set.
🎁 Are you founder or startup? Get 30 Notion Plus & AI for FREE with Partner link: https://affiliate.notion.so/experience