Repository URL to install this package:
|
Version:
1.0.1 ▾
|
| src |
| README.md |
| composer.json |
| dds_sendgrid.api.php |
| dds_sendgrid.info.yml |
| dds_sendgrid.install |
| dds_sendgrid.links.menu.yml |
| dds_sendgrid.module |
| dds_sendgrid.permissions.yml |
| dds_sendgrid.routing.yml |
This module adds a mail plugin for the Mailsystem module.
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 );
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 and default template used by this module, you can access them like this:
$sendgrid_config = \Drupal::config('dds_sendgrid.settings'); $api_key = $sendgrid_config->get('api_key'); $default_template = $sendgrid_config->get('default_template');
You can override both the API key and default template in your settings.php like this:
$config['dds_sendgrid.settings']['api_key'] = '<API_KEY>'; $config['dds_sendgrid.settings']['default_template'] = '<DEFAULT_TEMPLATE>';