Only show these results:

Google Pub/Sub for message sync

You can use Google Pub/Sub to sync Gmail messages between Google and Nylas in real-time. This guide explains how to set up PubSub for your project.

Automatic set up with a script

To simplify installation, Nylas maintains a script that you can run to automatically provision the GCP resources in Golang.


Your Pub/Sub Topic and related resources MUST be set up in the same Google app you use to authenticate accounts with Nylas.

  • Make sure that you have the PubSub and IAM APIs enabled in your GCP project. You can do this using the gcloud CLI tool:

        gcloud service enable
    gcloud service enable

Running the script

  1. Pull down the script from the nylas-samples/infra-setup repository, and change your directory to google-pubsub-sync.

    git clone
    cd infra-setup/google-pubsub-sync
  2. Switch the project setup to your GCP project.

    gcloud config set project $YOUR_GOOGLE_PROJECT_ID   
  3. Authenticate with GCP.

    Make sure that the account you authenticate with has permission to create PubSub and IAM resources.

    gcloud auth login
    gcloud auth application-default login
  4. Fetch the dependencies for the script.

    go get .   
  5. Execute the script.

    go run main.go --projectId $YOUR_GCP_PROJECT_ID   
    • To setup in environments other than US, use the --env flag. Supported values are us, eu and staging.
    go run main.go --projectId $YOUR_GCP_PROJECT_ID --env eu   
    • If the script fails with a 403 error with a message of SERVICE_DISABLED, make sure to enabled both the IAM and PubSub API in your project:
    gcloud services enable
    gcloud services enable
  6. Add the topic to the Nylas Dashboard.

    The topic name should be projects/$YOUR_GOOGLE_PROJECT_NAME/topics/nylas-gmail-realtime.

Manual set up


  • Make sure that you have an existing Google application connected to your Nylas application.

Your Pub/Sub Topic and related resources MUST be set up in the same Google app you use to authenticate accounts with Nylas.

Create a Service Account

  1. Open Service Accounts in the Google Cloud Platform console.

  2. Select your project and click Create Service Account.

  3. Name the account nylas-gmail-realtime.

    The name must be exactly nylas-gmail-realtime for the integration to work.

  4. Leave the Grant this service account access to project and Grant users access to this service account fields blank.

  5. Click Done.

Create a Pub/Sub topic

Your Pub/Sub Topic and related resources MUST be set up in the same Google app you use to authenticate accounts with Nylas.

  1. Search for "pub/sub" in the search bar and select Pub/Sub.

  2. Click CREATE TOPIC.

  3. Enter nylas-gmail-realtime for the topic ID and leave everything else as is. The topic ID listed is required for the integration to work.

  4. On the next page, if it's not already open, click SHOW INFO PANEL.

  5. In the panel, click ADD PRINCIPAL.

  6. Enter [email protected] in the New principals field.

  7. Set the role to Pub/Sub Publisher.

  8. On the Topics page, find the Subscriptions section and click nylas-gmail-realtime-sub.

  9. Select the subscription and click EDIT.

  10. Change the Delivery type to Push.

  11. Fill in the Endpoint URL field:

    • for the US, use
    • for the EU, use
  12. Select Enable Authentication and choose the service account you made in create a service account.

    If you're setting up multiple regions in a single GCP application, you'll need to create a subscription for each region.

  13. When prompted, grant the roles/iam.serviceAccountTokenCreator to your service account. If the prompt doesn't appear, follow the steps below to add the role to your service account:

    • From the main menu, navigate to IAM & Admin > Service Accounts
    • Copy the full service account email for the service account you created in create a service account (it should start with nylas-gmail-realtime).
    • Select the service account (it should be called nylas-gmail-realtime).
    • Navigate to the Permissions tab and make sure you're on the Principals tab at the bottom.
    • If the service account nylas-gmail-realtime-email isn't listed under principals, click Grant Access and paste the email into the New Principals field.
      • If it's listed, click the Edit icon next to that principal.
    • On the pop-up, click ADD ANOTHER ROLE.
    • Search for service account token creator.
    • Select the role.
    • Click SAVE.
  14. Under Expiration period, select Never expire

  15. Leave the other fields as they are and click Update. The screen saves your changes and returns to the Subscription page.

  16. Copy the Topic Name for the next step.

The topic name must be nylas-gmail-realtime and the principal must use the email [email protected] for Google Pub/Sub to work.

Add the Topic name to your dashboard

Before adding the Topic name, you need to enable Google Pub/Sub for your Nylas application.

  1. In the Nylas Dashboard, click App Settings.
  2. Click Authentication.
  3. In the Google Auth section, enter the topic you created in Create a Pub/Sub Topic in the GCP Topic Name field. For example, projects/nylas-test/topics/nylas-gmail-realtime.
  4. Repeat steps one to three for each Nylas app that needs real-time Gmail message sync.

Tip!: You can use the same Pub/Sub topic for all of your Nylas apps.