-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy paththreads.php
More file actions
54 lines (43 loc) · 1.39 KB
/
Copy paththreads.php
File metadata and controls
54 lines (43 loc) · 1.39 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
<?php
use Mailtrap\Config;
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
$inboxId = (int) ($_ENV['MAILTRAP_INBOUND_INBOX_ID'] ?? 0);
$threadId = $_ENV['MAILTRAP_INBOUND_THREAD_ID'] ?? '';
// Threads are scoped to an inbox.
$threads = (new MailtrapInboundClient($config))->threads($inboxId);
/**
* List conversation threads. Pass the previous page's last id to paginate.
*
* GET https://mailtrap.io/api/inbound/inboxes/{inbox_id}/threads
*/
try {
$response = $threads->getList();
var_dump(ResponseHelper::toArray($response));
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
/**
* Get a single thread with its messages embedded.
*
* GET https://mailtrap.io/api/inbound/inboxes/{inbox_id}/threads/{thread_id}
*/
try {
$response = $threads->getById($threadId);
var_dump(ResponseHelper::toArray($response));
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
/**
* Delete a thread.
*
* DELETE https://mailtrap.io/api/inbound/inboxes/{inbox_id}/threads/{thread_id}
*/
try {
$response = $threads->delete($threadId);
var_dump($response->getStatusCode());
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}