Only show these results:

Google Pub/Sub for Message Sync

If you're looking to sync data between Gmail and Nylas even faster, you can use Google Pub/Sub for real-time syncing of Gmail messages. This guide will take you through the set up process.

Automatic Setup With a Script

To simplify installation, there is a script that will automatically provision the GCP resources in Golang.


  1. Install Go
  2. Install the gcloud CLI tool here
  3. You'll need an existing Google application connected to your Nylas application.
  4. You'll need to have the PubSub and IAM APIs enabled in your GCP project. This can be done via the gcloud CLI tool:
    gcloud service enable
gcloud service enable

Running the Script

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

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

    gcloud config set project $YOUR_GOOGLE_PROJECT_NAME_HERE   
  3. Authenticate with GCP. Make sure that the account you authenicate with has permission to create PubSub resources and IAM resources

    gcloud auth application-default login   
  4. Open the main.go file and edit the ENV variable to the environment you want to use, and the ProjectId variable to be the project ID.

  5. Fetch the dependencies for the script

    go get .   
  6. Execute the script

    go run main.go   

    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 service enable
    gcloud service enable
  7. Add the topic to the Nylas Dashboard. The topic name will be projects/$YOUR_GOOGLE_PROJECT_NAME_HERE/topics/nylas-gmail-realtime

Manual setup


  1. You'll need an existing Google application connected to your Nylas application.

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 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. Leave the other fields as they are and click Update.

  15. After saving, it will take you back to the Subscription page. 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 on Authentication.
  3. Under the Google Auth section, input 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 every Nylas app you'd like to set up real-time Gmail message sync for.
    • You can use the same Pub/Sub topic for all of your Nylas apps.