Only show these results:

Set up Pub/Sub for your Google application

🔍 If you plan to use the Nylas Email API with Google, you must set up Pub/Sub. If you don't plan to use the Nylas Email API with your GCP app (for example, if you're creating a calendar-only project), you can skip this step.

Google's Pub/Sub subscription service allows you to receive webhook notifications from Google in a timely manner. You can either use the Nylas-maintained setup script to add Pub/Sub to your app, or set it up manually.

Before you begin

Before you set up Pub/Sub, you must have set up a Google provider auth app.

Add Pub/Sub with the Nylas script

To simplify the process of installing Pub/Sub, Nylas maintains a script that you can run to automatically provision the GCP resources in Golang.

Before you use the script, make sure your environment is set up properly:

⚠️ You must set up your Pub/Sub topic and its related resources in the Google auth app that you use to authenticate end users with Nylas.

When your environment is ready, download and run the Nylas script:

  1. Download the script from the Nylas infra-setup repository and change your local directory to google-pubsub-sync.

    git clone https://github.com/nylas-samples/infra-setup
    cd infra-setup/google-pubsub-sync
  2. Use the gcloud CLI to switch the project setup to your GCP app.

    gcloud config set project $YOUR_GOOGLE_PROJECT_ID   
  3. Authenticate with your GCP app. Make sure that the account you authenticate with has permission to create Pub/Sub and IAM resources.

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

    go get .   
  5. Run the script.

    go run main.go --projectId $YOUR_GCP_PROJECT_ID   
    • If you want to configure your GCP app in an environment other than the U.S., use the --env flag, as in the code snippet below. The flag supports the us, eu and staging values.

      go run main.go --projectId $YOUR_GCP_PROJECT_ID --env eu   
  6. Save the topic name.

If the script fails with a 403 error with a SERVICE_DISABLED message, make sure to enable both the IAM and Pub/Sub APIs in your project using the gcloud CLI:

gcloud services enable pubsub.googleapis.com
gcloud services enable iam.googleapis.com

Manually add Pub/Sub

To manually add Pub/Sub to your GCP app, you must create a service account and subscribe to a Pub/Sub topic.

Create a Google service account

First, create a service account in your GCP app:

  1. From the Google Cloud Platform dashboard, navigate to IAM & admin > Service accounts.
  2. Select your project and click Create service account.
  3. Name the account nylas-gmail-realtime.

    ⚠️ Keep in mind: The service account name must be exactly nylas-gmail-realtime for the Nylas connector to work.

  4. Optionally, add a description to the service account.
  5. Click Create and continue.
  6. Leave the Grant this service account access to project section blank and click Continue.
  7. Leave the Grant users access to this service account section blank.
  8. Click Done.

The following video walks through the process of creating a service account in the Google Cloud Platform dashboard.

Create a Pub/Sub topic

Next, create a Pub/Sub topic and subscribe to it.

⚠️ You must set up your Pub/Sub topic and its related resources in the Google auth app that you use to authenticate end users with Nylas.

  1. From the Google Cloud Platform dashboard, search for "pub/sub" and select Pub/Sub.

  2. Click Create topic.

  3. Enter nylas-gmail-realtime as the topic ID, and leave everything else as it is.

    ⚠️ Keep in mind: The topic ID must be exactly nylas-gmail-realtime for the Nylas connector to work.

  4. On the next page, click Show info panel if the panel is not already open.

  5. In the info panel, click Add principal.

  6. Enter [email protected] in the New principals field and set the role to Pub/Sub publisher.

  7. On the Topics page, find the Subscription section and click nylas-gmail-realtime-sub.

  8. Select the subscription and click Edit.

  9. Change the Delivery type to Push.

  10. Set the Endpoint URL:

    • For the U.S., use https://gmailrealtime.us.nylas.com.
    • For the E.U., use https://gmailrealtime.eu.nylas.com.

    📝 If you plan to use your GCP app for multiple Nylas regions, you must create a Pub/Sub subscription for each region.

  11. Select Enable authentication and choose the nylas-gmail-realtime service account.

  12. When prompted, grant the account the roles/iam.serviceAccountTokenCreator role. If the prompt doesn't appear, follow these steps to add the role manually:
    i. From the GCP dashboard, select IAM & admin > Service accounts.
    ii. Copy the full email address for the nylas-gmail-realtime service account. The email address should start with nylas-gmail-realtime.
    iii. Select the service account.
    iv. Navigate to the Permissions tab, then find the Principals tab at the bottom of the section.
    v. Find the nylas-gmail-realtime-email service account and click the Edit symbol next to it.

    • If the service account isn't listed, click Grant access and paste the email address in the New principals field.
      vi. A pop-up is displayed. Click Add another role.
      vii. Search for service account token creator and select the role.
      viii. Click Save.
  13. Under Expiration period, select Never expire.

  14. Leave the other fields as they are and click Update. Google saves your changes, and you're returned to the Subscription page.

  15. Save the topic name.

Add topic name to the Nylas Dashboard

Now that you have a Pub/Sub topic, you can add it to the Nylas Dashboard:

  1. From the Nylas Dashboard, click App settings > Authentication.
  2. In the Google auth section, enter the topic you created in the GCP topic name field (for example, projects/nylas-test/topics/nylas-gmail-realtime).

Repeat these steps for each Nylas application that needs real-time Gmail message sync.

💡 You can use the same Pub/Sub topic for all of your Nylas applications.