118 lines
2.4 KiB
Markdown
118 lines
2.4 KiB
Markdown
# BMail
|
|
|
|
The BMail package allows you to send email templates with Laravel to the Bluescale API.
|
|
|
|
## Installation
|
|
|
|
First in your composer.json, add :
|
|
|
|
```bash
|
|
"require": {
|
|
"bluescale/laravel-bmail": "dev-master"
|
|
}
|
|
```
|
|
|
|
and
|
|
|
|
```bash
|
|
"repositories": [
|
|
{
|
|
"type": "vcs",
|
|
"url": "git@git.bluesquare.io:bluescale/laravel-bmail.git"
|
|
}
|
|
]
|
|
```
|
|
|
|
Next update your package :
|
|
|
|
```bash
|
|
composer update bluescale/laravel-bmail
|
|
```
|
|
|
|
Then publish the assets from your provider :
|
|
|
|
```bash
|
|
php artisan vendor:publish
|
|
```
|
|
|
|
Finally get your API key :
|
|
|
|
```bash
|
|
Connect to https://bluescale.email, go to the Templates tab, click on the API button and copy your API key.
|
|
```
|
|
|
|
And add it in your .env, along with the API URL :
|
|
|
|
```bash
|
|
BMAIL_API_KEY=your_api_key
|
|
BMAIL_API_URL=https://bluescale.email/api/project/template/send
|
|
```
|
|
|
|
## Usage
|
|
|
|
First, create a new notification or use an existing one :
|
|
|
|
```bash
|
|
php artisan make:notification BMailNotification
|
|
```
|
|
|
|
Next, add a public field '$template_id' to your class, which will be initialized in the constructor :
|
|
|
|
```bash
|
|
public $template_id;
|
|
|
|
/**
|
|
* BMailNotification constructor.
|
|
* @param string $template_id
|
|
*/
|
|
public function __construct(string $template_id)
|
|
{
|
|
$this->template_id = $template_id;
|
|
}
|
|
```
|
|
|
|
Then, in the via method add :
|
|
|
|
```bash
|
|
return [BMailChannel::class];
|
|
```
|
|
|
|
Then, create a 'toTemplate()' method, in which you specify your template fields :
|
|
|
|
```bash
|
|
public function toTemplate($notifiable)
|
|
{
|
|
return (new BMailTemplate($this->template_id))
|
|
->sender("john.doe@gmail.com", "John OPTIONNAL") OPTIONNAL
|
|
->replyTo("jean.grey@gmail.com", "Jean OPTIONNAL") OPTIONNAL
|
|
->recipients([
|
|
[
|
|
"elvis@gmail.com", [
|
|
"name" => "Elvis" OPTIONNAL,
|
|
"parameters" => ["key" => "value"] OPTIONNAL
|
|
]
|
|
],
|
|
[
|
|
"robert@gmail.com"
|
|
]
|
|
])
|
|
->addRecipient("edward@gmail.com")
|
|
->parameters(["key" => "value", "key" => "value"])
|
|
->addParameter("key", "value");
|
|
}
|
|
```
|
|
|
|
Finally, get the template's id :
|
|
|
|
```bash
|
|
Go to https://bluescale.email, Templates tab, click on the template you want to use and copy the template identifier.
|
|
```
|
|
|
|
And from your controller, send a notification for a user :
|
|
|
|
```bash
|
|
User::find('user_id')->notify(new BMailNotification('template_id'));
|
|
```
|
|
|
|
|