price2performance / sendgrid-nette
Sendgrid integration for Nette.
v2.0.1
2020-06-09 09:03 UTC
Requires
- php: >=7.1
- nette/di: ^3.0
- nette/mail: ^3.0
- sendgrid/sendgrid: ^7.4
Requires (Dev)
- latte/latte: ^2.7
- mockery/mockery: ^1.3
- nette/application: ^3.0
- nette/bootstrap: ^3.0
- nette/tester: ^2.3
This package is auto-updated.
Last update: 2024-12-21 22:23:26 UTC
README
Sendgrid integration for Nette.
Install
composer require price2performance/sendgrid-nette
Configuration
In config add:
extension:
sendgrid: Price2Performance\SendGrid\DI\SendGridExtension
sendgrid:
key: 'SECRET_KEY'
Usage
To make any API call to SendGrid, just inject the SendGrid class to your presenter:
/** @var SendGrid @inject */ public $sendgrid; public function actionDefault() { // CALL suppression/bounces try { $response = $this->sendgrid->client->suppression()->bounces()->get(); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; } catch (Exception $e) { echo 'Caught exception: '. $e->getMessage(). "\n"; } }
To send an email via SendGrid
, just inject Price2Performance\SendGrid\SendGridMailer
to your presenter:
/** @var \Price2Performance\SendGrid\SendGridMailer @inject */ public $mailer; protected function sendMail() { $message = new \Nette\Mail\Message(); $message->addFrom('sender@example.com', 'Sender Name'); $message->addTo('example@example.com'); $message->setSubject('TEST SUBJECT'); $message->setBody('TEST BODY'); $this->mailer->send($message); /** @var \SendGrid\Response $response */ $response = $this->mailer->getLastResponse(); // optional, for error logging }
Calling getLastResponse()
on SendGridMailer
gets you SendGrid\Response
of the last send()
call. You can use it to log errors.