# Set up the Nylas package in Salesforce

Source: https://developer.nylas.com/docs/unlisted/nylas-package-in-salesforce/

> **Info:** 
> 🔍 **The Nylas package is compatible with Nylas v3 only**. If you're currently using Nylas v2.7 or earlier, see the [Upgrade guides](/docs/v2/upgrade-to-v3/) for information on migrating to v3.

Nylas offers a Salesforce package that you can use to sync email messages and events into your Salesforce instance, so they're available to your users. This page explains how to set up the Nylas package.

## How the Nylas Salesforce package works

After you install and set up the Nylas package in Salesforce, it syncs email messages and events into your Salesforce instance using automated object matching logic.

Nylas syncs email messages and events in any of the following scenarios:

- When any email address in the `to`, `from`, or `participants` fields matches the email address for a known lead or contact in your Salesforce instance. If the lead or contact is associated with an Opportunity, Salesforce automatically links the email message or event to that Opportunity as well.
- When the domain of an email address in the `to`, `from`, or `participants` fields matches the domain of a known account in your Salesforce instance. For example, a message from an email address ending in `@nylas.com` would be synced with the Nylas account.

The Nylas package also includes a lightning web component, the `nylasV3AccountInbox`, which you can drag and drop onto page layouts for accounts, leads, and contacts. The component provides a responsive and intuitive way for your end users to browse the email messages and events that Nylas synced for a specific record.

## Set up the Nylas Salesforce package

Before you set up the Nylas package in your Salesforce instance, you first need to [set up your Nylas application](/docs/v3/getting-started/) and create at least one [connector](</docs/api/v3/admin/#tag--Connectors-(Integrations)>).

> **Info:** 
> 🔍 **You must have a Salesforce Professional or Enterprise edition to use the Nylas Salesforce package**. The package uses Salesforce sites that are only available on these editions.

## Install the Nylas package

> **Success:** 
> ✨ **The latest version of the Nylas Salesforce package is v2.0.3**.

First, install the Nylas package and grant it access to the Nylas API URL:

1. In Salesforce, run the [installation package](https://login.salesforce.com/packaging/installPackage.apexp?p0=04tQk000000KPYXIA4).
1. Select **Install for all users**, and click **Install**.
   ![The NylasV3 installation package showing the installation options.](/_images/salesforce/installation.png "NylasV3 Salesforce package")
1. Check **Yes, grant access to these third-party web sites** to allow Salesforce to access the Nylas API URL, then click **Continue**.
   ![The Salesforce "Approve Third-Party Access" pop-up displaying a list of third-party websites requesting access to the Salesforce instance.](/_images/salesforce/third-party-access.png "Approve third-party access")

## Set up a Nylas webhook listener

Next, you'll set up a Nylas webhook listener.

- [Set up a Nylas webhook listener site in Salesforce](#set-up-a-nylas-webhook-listener-site).
- [Enable the Apex class for the webhook listener](#enable-the-apex-class).
- [Assign a permission set to the webhook listener users](#assign-permissions-to-webhook-listener-users).

### Set up a Nylas webhook listener site

First, you need to set up a site to listen for webhooks from Nylas:

1. In Salesforce Lightning Experience, click **Setup > Sites** in the top menu bar. If you haven't already registered your Salesforce site domain, follow the instructions on the page to register it.
2. Click **New**.
3. Enter a name for the site in the **Site label** field (for example, "NylasWebhookListener").
4. Select **Active** and set **Active site home page**. Nylas recommends you use the default, `InMaintenance`.
5. **Save** your changes.

### Enable the Apex class

Next, enable the Apex class for the webhook listener site. This allows the site to process incoming messages.

1. On the **Sites** page, select the webhook listener site that you created.
2. Click **Public access settings > Enabled Apex class access**.
   ![The Salesforce site profile page displaying a list of administration options. "Enabled Apex Class Access" is outlined in red.](/_images/salesforce/enabled-apex-class.png "Enabled Apex class access")
3. Click **Edit**.
4. Select `nylas.Rest_NylasV3WebhookListener` in the **Available Apex classes** list, and click **Add**. This provides the REST resource that handles incoming messages from the Nylas API.
   ![The "Available Apex Classes" list with the webhook listener class added.](/_images/salesforce/apex-class.png "Enable the Apex class")
5. **Save** your changes.

### Assign permissions to webhook listener users

You also need to assign permissions to the Nylas webhook listener guest users:

1. On the **Setup** page, enter "Guest user" in the search bar and select the first result.
2. Under "Users", choose the guest user for the webhook listener site that you created (for example, "NylasWebhookListener Site Guest User").
3. Click **Permission set assignments > Edit assignments**.
4. Select **Nylas application webhook guest user** from the **Available permission sets** list, then click **Add**.
   ![The "Guest User Permissions" list with the webhook guest user permissions added.](/_images/salesforce/guest-user-permissions.png "Add guest user permissions")
5. **Save** your changes.

## Enable Nylas billing

Now that your webhook listener is set up, you need to enable Nylas billing for your Salesforce instance:

1. In Salesforce Lightning Experience, click the **App launcher** symbol at the top-left of the page.
2. Enter "Nylas" in the search bar and select the application.
3. Click **Nylas admin > Go to Nylas billing**.
4. Follow the instructions in the billing portal to activate your Nylas account.
5. When your payment is processed, Nylas sends an activation email message to the email address you specified in the billing portal. Copy the activation code from the email and paste it in the **Activation code** field in the billing portal.
6. Click **Provision application**.

### Verify provisioned application

Nylas recommends you verify your application was provisioned successfully after you enable billing.

1. In Salesforce Lightning Experience, click **Setup > Custom metadata types** in the top menu bar.
2. Navigate to **Nylas v3 setting > Manage Nylas v3 settings > nylas\_\_System_Config**.
3. If your application was provisioned successfully, the **Callback URI**, **Client ID**, **Nylas API secret**, **Webhook secret**, and **Region** fields will be populated with your application information.

## Assign permissions to Nylas admin users

Now that your Nylas application is provisioned to Salesforce, you need to assign permissions to your Nylas admins:

1. In Salesforce Lightning Experience, click **Setup** in the top menu bar.
2. Enter an admin's username in the search bar and select their account.
3. On the **User** page, click **Permission set assignments > Edit assignments**.
4. Select **Nylas application admin** from the **Available permission sets** list, then click **Add**.
5. **Save** your changes.

Repeat these steps for each of your admin users.

## Authenticate users

Finally, [assign a permission set to your end users](#assign-permissions-to-application-users) and [authenticate their accounts](#authenticate-users-with-nylas-hosted-auth) to sync email messages into your Salesforce instance.

### Assign permissions to application users

1. In Salesforce Lightning Experience, click **Setup** in the top menu bar.
2. Enter a user's username in the search bar and select their account.
3. On the **User** page, click **Permission set assignments > Edit assignments**.
4. Select **Nylas application user** from the **Available permission sets** list, then click **Add**.
5. **Save** your changes.

Assigning this permission set allows your users to access the Nylas application in the Salesforce App Launcher, and view the **Nylas setup** tab in the application.

Repeat these steps for each of your Nylas users.

### Authenticate users with Nylas Hosted Auth

Now that your application users have permissions assigned to their accounts, you can authenticate them:

1. In Salesforce Lightning Experience, click the **App launcher** symbol at the top-left of the page.
2. Enter "Nylas" in the search bar and select the application.
3. Click **Nylas setup > Auth your email with Nylas**.
4. Follow the instructions on the page to complete the Hosted authentication flow.

When the account is successfully authenticated, Nylas populates the following fields on the **User** page:

- **Authed Nylas v3 integration**
- **Nylas v3 integration authed date**
- **Nylas grant ID**

![A close-up of the Salesforce interface showing the "Authed Nylas v3 integration", "Nylas v3 integration authed date", and "Nylas grant ID" fields.](/_images/salesforce/auth-fields.png "Nylas authentication information in Salesforce")

When you refresh the **Nylas admin** tab, Salesforce displays a list of authenticated grants in the **Grants** table.

## Keep in mind

- You can configure email and event sync settings in the **Nylas setup** tab.
- You can view inbound webhook logs in the **Nylas logs** tab. If you want to see all logs instead of only the most recent, you need to set up a new view.