To create a subscriptionId for Gmail Push Notifications using Google Pub/Sub, follow these steps:
Prerequisites:
-
A Google Cloud Project
-
Gmail API and Pub/Sub API enabled
-
A Pub/Sub topic created in the same project
-
A service account with Pub/Sub Publisher and Gmail API permissions
-
Domain-wide delegation enabled (if accessing multiple users)
🔧 Step-by-Step: Creating a subscriptionId
🔹 Step 1: Create a Pub/Sub Topic
Go to the Google Cloud Console:
-
Navigate to Pub/Sub > Topics
-
Click "Create Topic"
-
Name it:
projects/YOUR_PROJECT_ID/topics/YOUR_TOPIC_NAME
🔹 Step 2: Create a Subscription to That Topic
Once your topic is created:
-
Go to Pub/Sub > Subscriptions
-
Click "Create Subscription"
-
Set:
-
Subscription ID: e.g.,
gmail-updates-sub
-
Topic: Select your topic
-
Delivery Type: Usually Push
-
Endpoint URL: Must be an HTTPS endpoint that can receive Gmail push events (e.g., a webhook)
-
🔹 Step 3: Grant Gmail Publish Rights
Gmail publishes to Pub/Sub using a special service account:
-
Email:
gmail-api-push@system.gserviceaccount.com
So, go to IAM > Permissions for your topic and:
-
Add a new member:
gmail-api-push@system.gserviceaccount.com
-
Role:
Pub/Sub Publisher
🔹 Step 4: Use subscriptionId
in Your App (optional)
While Gmail uses the topic name, you can use the subscription on your server to receive and process messages.
🧪 Testing
You can publish a test message in the Pub/Sub topic, and verify your endpoint (or logging) receives the notification.
🧠Notes
-
Gmail doesn't use the subscription ID directly. It publishes to the topic, and you subscribe to the topic to receive notifications.
-
Your Windows Service should either:
-
Periodically check using
HistoryId
polling (simpler) -
OR have a separate HTTP endpoint (like a web server or Azure Function) to receive real-time push
-
Sign up here with your email
ConversionConversion EmoticonEmoticon