Repository URL to install this package:
|
Version:
2.0.2 ▾
|

This module adds a mail plugin for the Mailsystem module.
The settings page can be found under Configuration -> Web services -> SendGrid Settings or /admin/config/services/sendgrid.
As such it is only handling mails sendt through said Mailsystem module, if you need to manually use the SendGrid API, the PHP library that is required by this module will allow you to do that.
$site_settings = \Drupal::config('system.site'); $parameters = [ 'to' => 'Dion Sune Jensen <dsj@novicell.dk>', 'subject' => 'This is just a test', 'body' => '<strong>Test content</strong>', 'from_name' => 'Novicell', 'reply-to' => 'Dion Sune Jensen <dsj@novicell.dk>', 'sendgrid' => [ 'dynamic_template_data' => [ 'test_dynamic_tag' => 'This is a dynamic tag' ] ] ]; if ($site_settings->get('name')) { $from = $site_settings->get('name') . ' <' . $site_settings->get('mail') . '>'; } else { $from = $site_settings->get('mail'); } // You can dump the $result to get the sending status and result. $result = \Drupal::service('plugin.manager.mail')->mail( 'dds_sendgrid', 'sendgrid_test', $parameters['to'], \Drupal::languageManager()->getCurrentLanguage()->getId(), $parameters, $from );
The sendgrid key in the parameters array contains the various settings to pass to the sendgrid API.
| Key | Description | Type |
|---|---|---|
bypass_list_management |
Allows bypassing of the list management, meaning that it won't check if the email belongs to a list | Boolean |
spam_check |
Enable or disable the spam check. | Boolean |
template_id |
The template id of the Transactional template to use when sending the mail. | String |
substitutions |
An array of substitutions keyed by the substitution tag with the value it should replace the tag with. | String[] |
dynamic_template_data |
Like substitutions, but allows them to be used for template handlebars logic | String[] |
include_test_attachment |
Adds a test attachment (The Druplicon logo) to the message | Boolean |
If you want to send mail without using the Mailsystem, you will have to use the SendGrid PHP library to do it.
To access the API key used by this module, you can access them like this:
$sendgrid_config = \Drupal::config('dds_sendgrid.settings'); $api_key = $sendgrid_config->get('api_key');
You can override the API key in your settings.php like this:
$config['dds_sendgrid.settings']['api_key'] = '<API_KEY>';