Using SendGrid To Deliver Email

Detailed information on using SendGrid to deliver email through your WordPress and Drupal site.

Contributors: Erik Mathy, Brian Thompson, Brent Connor, Sarah German, Steven DuBois.

Discuss in our Forum Discuss in Slack

Email is a necessity when running a website, whether it's used with a simple contact form or to manage subscription based services, odds are you’re going to need it. Users may want to receive notices of content updates, have sales receipts sent to them, update their password or membership information, and more. Email is the most effective way of communicating with a site's user base, but it does no good if these messages are filtered and marked as spam.

One of the most common reasons that email gets blocked is because it originates from a website hosted by a third party service, like Pantheon. In order to ensure this doesn't happen to you, we at Pantheon highly encourage using your own email server or a service provider such as SendGrid.

 Note

New Sendgrid account may need to wait 30 days before upgrading to a paid plan. If you're switching to Sendgrid from an existing email solution, make sure to plan for this.

Why SendGrid?

SendGrid has a lot of things going for it, all of which do the hard work for you when it comes to how mail is managed on your site. It can handle massive email campaigns while providing highly detailed and flexible reporting, along with the ability to scale and increase deliverability.

Create a SendGrid Account

  1. Get started by signing up for an account and selecting a plan that meets your business needs. After receiving your confirmation email, sign in to your SendGrid account.

  2. From within the Settings menu, click API Keys:

    SendGrid Multiple User setup

  3. Click Create API Key to define the name and permissions for the API key your site will use. Click Create & View to complete the process.

  4. The API key will only be displayed once. Copy the key and save it somewhere secure until you can apply it to the site.

  5. From the Settings Menu click Sender Authentication. SendGrid requires accounts created after April 6th 2020 to identify their sender identity through either Domain Authentication or Single Sender Verification. A more detailed explanation of these options can be found in the SendGrid Documentation.

Integrating Sendgrid With Drupal and WordPress

Follow the procedure outlined below for your CMS:

The official Sendgrid plugin has not been updated for the latest several major releases of WordPress. You can still use it, or consider another plugin like WP Mail SMTP.

When using SendGrid with Drupal 8, we recommend using the SendGrid Integration module. While you can use the SMTP Authentication Support module to send mail to SendGrid over SMTP, our testing (as of the last update) was hampered by a known issue with the module recognizing the presence of a required PHP library.

 Warning

The SendGrid API Integration Module for Drupal 8 requires a Composer managed workflow as described in our Build Tools or Drupal 8 and Composer on Pantheon Without Continuous Integration guides. We cannot support non-Composer workflows using this module. For details, see the module readme file.

  1. Install the SendGrid Integration module using Composer:

    composer require drupal/sendgrid_integration
  2. Commit, push, and enable the new module. Replace $SITE and $ENV with the site and environment name:

    git add .
    git commit -m "Install sendgrid_integration"
    git push origin master #Or Multidev name
    terminus drush $SITE.$ENV -- en sendgrid_integration -y
  3. Visit /admin/config/services/sendgrid once you've logged into your Drupal site as an administrator. Paste your API Key and click Save Configuration.

Your Drupal application on Pantheon is now set up to send email through SendGrid's API. Test your configuration from /admin/config/services/sendgrid/test.

Choosing an Integration Method

Two methods can be used to integrate SendGrid with your Drupal 7 site: API or SMTP.

Considerations

  • SMTP requests are associated with dynamic outgoing IPs, which can have a negative impact on deliverability.
  • API integration using the SendGrid Integration module is recommended; however, installation of this module is slightly more complicated, as it requires the use of Composer. For Drupal 7 we can utilize the dev release of this module and use Composer in a non-invasive manner that is compatible with upstream updates.

Your Drupal application on Pantheon is now set up to send email through SendGrid. Provide an address within the Send Test E-mail configuration field and click Save configuration to test.

Checking Deliverability in SendGrid

For testing purposes, your first few deliveries should be to email addresses that you control directly. You can track and measure unique aspects of mail behaviors from within your site's SendGrid account, which should be monitored regularly.

First, log into SendGrid and select Activity. You will be taken to a page with a form to search by email. Enter the email address, and press Enter. SendGrid will search through your mail queue for any messages sent to that address. For additional search parameters, select the filters near the top right corner.

SendGrid email search options

You can explore the Statistics and Email Reports from within your site's account to gain insight into email activity, statistics on email clients, and much more.

Congratulations!

You have now successfully integrated an industrial strength, simple to use, email delivery service into your website. If you have any questions, contact SendGrid's support team or check out SendGrid’s Email Infrastructure Guide for advanced tips on how to create and publish DNS records for increased deliverability.

Troubleshooting

In some cases, other WordPress plugins can conflict with the Sendgrid plugin and cause it to use PHPMailer instead of SendGrid.

See Also