Skip to main content
Last Reviewed: 2026-06-15

Drupal Key Usage

How to configure Sendgrid using Pantheon Secrets with Drupal's Key module.


If you want to use Pantheon Secrets in your Drupal application through the Key module, you should use the Pantheon Secrets module.

Pantheon Secrets detailed example

In this guide we will go over an end-to-end example on how to setup secrets for a given site and how to use those secrets on a module that integrates with the Key module. For this example, we will use the SendGrid API and SendGrid Mailer modules.

Prerequisites

  • Make sure you have access to a Drupal 9.4 or 10 site running PHP 8.0 or above hosted on Pantheon.

    Information:
    Note

    The SendGrid Mailer module used in this example does not support Drupal 11. If you are running Drupal 11, you will need to use a different mail module.

  • Make sure you have Terminus 4.2.0 or later installed on your local machine.

Steps

  1. Install the required modules in your Drupal site and push the changes to Pantheon:

  2. Enable the modules:

  3. Make sure your SendGrid account is correctly configured and allows sending email.

  4. Create a SendGrid API key by following the SendGrid instructions.

  5. Store the API key as a site secret:

    Alternatively, you can set this secret via the Site Dashboard. See Create a new secret for dashboard instructions.

    Create new secret in the dashboard with options for type and scope

    As a best practice, the non-production environments should be the default and then override that value with a secret environment override to change the API key for the live environment (for example, if you want to use different SendGrid accounts for live and dev environments).

  6. Add the Key entity in one of the different available ways:

    • Option 1: Manually

      Go to /admin/config/system/keys and click Add key. Select Pantheon Secret as the key provider and your secret name from the dropdown (make sure you select "SendGrid" as the Key type and "Pantheon" as the Key provider)

      Screenshot of creating a new Key entity with type "Sendgrid" and provider "Pantheon"

    • Option 2: Sync Keys via Drupal Admin

      Go to /admin/config/system/keys/pantheon and click on the "Sync Keys" button to get all of the available secrets into Key entities.

      Screenshot of Sync Pantheon Secrets page in Drupal UI

      Then, go to /admin/config/system/keys to edit the sendgrid_api Key and change the type to "SendGrid".

    • Option 3: Sync Keys via Terminus

      Use the provided Drush command to sync all of your secrets into Key entities:

      Then, go to /admin/config/system/keys to edit the sendgrid_api Key and change the type to "SendGrid".

  7. Go to the SendGrid API Configuration page (/admin/config/services/sendgrid) and select your Key item.

    Screenshot of Sendgrid API Configuration page in Drupal UI

  8. Make sure your site "Email Address" (/admin/config/system/site-information) matches a verified Sender Identity in SendGrid.

  9. Go to the Default Mail System Configuration page (/admin/config/system/mailsystem) and set Formatter and Sender to SendGrid Mailer.

  10. Go to the SendGrid email test page (/admin/config/services/sendgrid/test) and test your SendGrid integration by sending a test email.

    Screenshot of Sendgrid email test page in Drupal UI

  11. The email should get to your inbox. Enjoy!