diff --git a/README.md b/README.md index b4acdfc..f6c8a9f 100644 --- a/README.md +++ b/README.md @@ -155,6 +155,11 @@ MailService::retry($result['id']); MailService::cancel($result['id']); MailService::templates(); MailService::health(); + +// стоп-лист проекта +MailService::suppress('ivan@example.com', 'complaint', 'пожаловался на спам'); +MailService::suppressions(['reason' => 'bounce']); +MailService::unsuppress('ivan@example.com'); ``` Методы клиента: @@ -168,8 +173,14 @@ MailService::health(); | `retry($id)` | вернуть письмо в очередь | | `cancel($id)` | отменить письмо | | `templates()` | список шаблонов | +| `suppressions($filters)` | стоп-лист: кому проект больше не пишет | +| `suppress($email, $reason, $note)` | закрыть адрес | +| `unsuppress($email)` | открыть адрес обратно | | `health()` | состояние сервиса | +Шаблоны и транспорты у ключа свои: видно то, что принадлежит владельцу проекта, +плюс общие транспорты. Чужого имени для проекта не существует. + Письмо `Message` собирается цепочкой (без Laravel Mail, напрямую в API): ```php diff --git a/src/Client.php b/src/Client.php index 23db631..5c21648 100644 --- a/src/Client.php +++ b/src/Client.php @@ -116,6 +116,47 @@ class Client return $this->sendJson('GET', '/api/v1/templates'); } + /** + * Стоп-лист: адреса, которым сервис больше не пишет. Письмо такому адресу + * отсеивается на приёме, а если закрыты все получатели — письмо получает + * статус suppressed и никуда не уходит. + * + * @param array $filters reason, search, page, per_page + * @return array + */ + public function suppressions(array $filters = []): array + { + return $this->sendJson('GET', '/api/v1/suppressions', $filters); + } + + /** + * Закрыть адрес: писать ему больше не будем. + * + * @param string $reason bounce, complaint, unsubscribe или manual + * @return array + */ + public function suppress(string $email, string $reason = 'manual', string $note = ''): array + { + $payload = ['email' => $email, 'reason' => $reason]; + + if ($note !== '') { + $payload['note'] = $note; + } + + return $this->sendJson('POST', '/api/v1/suppressions', $payload); + } + + /** + * Открыть адрес обратно. Адрес, закрытый для всех проектов сразу (так ложатся + * отказы почтовых серверов), через API не снять — только в панели. + * + * @return array + */ + public function unsuppress(string $email): array + { + return $this->sendJson('DELETE', '/api/v1/suppressions/' . rawurlencode($email)); + } + /** * Состояние сервиса. * diff --git a/src/Facades/MailService.php b/src/Facades/MailService.php index 5212131..03530ef 100644 --- a/src/Facades/MailService.php +++ b/src/Facades/MailService.php @@ -16,6 +16,9 @@ use Rsgrinko\MailServiceSdk\Message; * @method static array retry(string $id) * @method static array cancel(string $id) * @method static array templates() + * @method static array suppressions(array $filters = []) + * @method static array suppress(string $email, string $reason = 'manual', string $note = '') + * @method static array unsuppress(string $email) * @method static array health() * * @see \Rsgrinko\MailServiceSdk\Client