# Send (transactional) mails via Campaign Monitor

## Installation

To publish the config file to `config/campaignmonitor.php` run:

```bash
php artisan vendor:publish --provider="Tricks\CampaignMonitor\CampaignMonitorServiceProvider"
```

This will publish a file `campaignmonitor.php` in your config directory with the following contents:
```php
return [
    'transactional' => [
        'api_key' => env('CAMPAIGNMONITOR_TRANSACTIONAL_API_KEY'),
        'client_id' => env('CAMPAIGNMONITOR_TRANSACTIONAL_CLIENT_ID'),

        'mails' => [
            'dummy' => [
                'id' => '636b7b95-2bd7-4d23-b206-3dbe701d7253',
                'recipient' => 'foo@dev.tricks.de',
                'rules' => [
                    'test1' => 'required',
                    'test2' => 'required',
                ]
            ]
        ]
    ],
];
```

## Usage

The package defines API routes for sending the respective mail via Campaign Monitor. You can get a hold of them via `php artisan route:list | grep api.campaignmonitor.transactional`.
Your corresponding frontend can send a (Sanctum authorized) POST request with the variables defined in the config.

An example call from a frontend (www.acme.com) to the API hosting backend (api.acme.com) could look like this (using cURL):

```bash
curl 'https://api.acme.com/api/campaignmonitor/transactional/quick' \
  -H 'Accept: application/json, text/plain, */*' \
  -H 'X-XSRF-TOKEN: eyJpdiI6ImRvSFB2RGYya2h6Wkd5Z09FMVYzMWc9PSIsInZhbHVlIjoiS1VKbzBrd3JTckZQTUFUUWFOY0hGQWIzeWJIb2VIdysrdmFyNndNUzRXRW9qRmVlUUlqWmdmb24yTmw4YkUyZVRXNXRIMnlQTzBndzJIQzRQMHNTQVZ6QWx6dVZGdlp5d2NqbFBENENIUTk4NEU4emJGNXNGL296L0U0VVFpMFkiLCJtYWMiOiI1YTU3ZTk0M2JjZDRlYmJmMGQ3ODNkMGE1Mzc5NGUzZmMxODg4MThmNWI5NTcyNTg4Yzc0MTJkNmZmM2NiODJiIn0=' \
  -H 'X-Requested-With: XMLHttpRequest' \
  -H 'Content-Type: application/json;charset=UTF-8' \
  -H 'Origin: https://www.acme.com/' \
  -H 'Referer: https://www.acme.com/' \
  -H 'Cookie: acme_session=eyJpdiI6IkpJQmxuaXFCL0lwd3N6c1JIRHNtV1E9PSIsInZhbHVlIjoiZTZlMU0wQXV0VFNHVmlCNm4zaU85d0tHSUtuKzd2aHNLdDhpMWVzWjJPSEF5akpMcGFRZ2ZyVE85TWVMaDF0QXZZRmNMSk9GQ0cxYlMrVndCMXU2WEJ6ZEZUMmhRVnhIWk83cy9Ta3liZzJ2U0d2dU03cHFHSGlMSktDVTVGNG0iLCJtYWMiOiJkMTY3YjNhZDg2YjZiNGVkMzI1MjlhYTE0MjJlMTY5NmNhNTJjMDY3N2JmNzM5MGViYTIyY2Y4OWI3NDc3ODU0In0%3D' \
  --data-raw '{"test1":"foo","test2":"bar"}'
```