-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathinboxes.php
More file actions
85 lines (70 loc) · 2.22 KB
/
Copy pathinboxes.php
File metadata and controls
85 lines (70 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
use Mailtrap\Config;
use Mailtrap\DTO\Request\Inbound\CreateInboundInbox;
use Mailtrap\DTO\Request\Inbound\UpdateInboundInbox;
use Mailtrap\Helper\ResponseHelper;
use Mailtrap\MailtrapInboundClient;
require __DIR__ . '/../../vendor/autoload.php';
$config = new Config($_ENV['MAILTRAP_API_KEY']); #your API token from here https://mailtrap.io/api-tokens
$folderId = (int) ($_ENV['MAILTRAP_INBOUND_FOLDER_ID'] ?? 0);
$inboxId = (int) ($_ENV['MAILTRAP_INBOUND_INBOX_ID'] ?? 0);
// Inboxes are scoped to a folder.
$inboxes = (new MailtrapInboundClient($config))->inboxes($folderId);
/**
* List inboxes in the folder.
*
* GET https://mailtrap.io/api/inbound/folders/{folder_id}/inboxes
*/
try {
$response = $inboxes->getList();
var_dump(ResponseHelper::toArray($response));
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
/**
* Create an inbox. Omit the domain id for a Mailtrap-hosted inbox; pass it to
* create a custom-domain (catch-all) inbox.
*
* POST https://mailtrap.io/api/inbound/folders/{folder_id}/inboxes
*/
try {
$response = $inboxes->create(
new CreateInboundInbox('Tickets', $_ENV['MAILTRAP_INBOUND_DOMAIN_ID'] ?? null)
);
var_dump(ResponseHelper::toArray($response));
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
/**
* Get an inbox by ID.
*
* GET https://mailtrap.io/api/inbound/folders/{folder_id}/inboxes/{inbox_id}
*/
try {
$response = $inboxes->getById($inboxId);
var_dump(ResponseHelper::toArray($response));
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
/**
* Rename an inbox.
*
* PATCH https://mailtrap.io/api/inbound/folders/{folder_id}/inboxes/{inbox_id}
*/
try {
$response = $inboxes->update($inboxId, new UpdateInboundInbox('Tickets (renamed)'));
var_dump(ResponseHelper::toArray($response));
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
/**
* Delete an inbox.
*
* DELETE https://mailtrap.io/api/inbound/folders/{folder_id}/inboxes/{inbox_id}
*/
try {
$response = $inboxes->delete($inboxId);
var_dump($response->getStatusCode());
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}