-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathall.php
More file actions
97 lines (74 loc) · 2.62 KB
/
all.php
File metadata and controls
97 lines (74 loc) · 2.62 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
86
87
88
89
90
91
92
93
94
95
96
97
<?php
declare(strict_types=1);
use Mailtrap\Config;
use Mailtrap\Helper\ResponseHelper;
use Mailtrap\MailtrapSendingClient;
require __DIR__ . '/../../vendor/autoload.php';
$accountId = (int) $_ENV['MAILTRAP_ACCOUNT_ID'];
$config = new Config($_ENV['MAILTRAP_API_KEY']); #your API token from here https://mailtrap.io/api-tokens
$sendingDomains = (new MailtrapSendingClient($config))->domains($accountId); #required parameter is accountId
/**
* Get a list of sending domains.
*
* GET https://mailtrap.io/api/accounts/{account_id}/domains
*/
try {
$response = $sendingDomains->getSendingDomains();
// print the response body (array)
var_dump(ResponseHelper::toArray($response));
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
/**
* Create a new sending domain
*
* POST https://mailtrap.io/api/accounts/{account_id}/domains
*/
try {
$domainName = 'example.com';
$response = $sendingDomains->createSendingDomain($domainName);
// print the response body (array)
var_dump(ResponseHelper::toArray($response));
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
/**
* Get a sending domain by ID
*
* GET https://mailtrap.io/api/accounts/{account_id}/domains/{domain_id}
*/
try {
$domainId = (int) $_ENV['MAILTRAP_DOMAIN_ID']; // Set this environment variable with a valid domain ID
$response = $sendingDomains->getDomainById($domainId);
// print the response body (array)
var_dump(ResponseHelper::toArray($response));
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
/**
* Send domain setup instructions
*
* POST https://mailtrap.io/api/accounts/{account_id}/domains/{domain_id}/send_setup_instructions
*/
try {
$domainId = (int) $_ENV['MAILTRAP_DOMAIN_ID']; // Set this environment variable with a valid domain ID
$email = 'devops@example.com'; // Email address to send setup instructions to
$response = $sendingDomains->sendDomainSetupInstructions($domainId, $email);
// print the response body (array)
var_dump(ResponseHelper::toArray($response));
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
/**
* Delete a sending domain
*
* DELETE https://mailtrap.io/api/accounts/{account_id}/domains/{domain_id}
*/
try {
$domainId = (int) $_ENV['MAILTRAP_DOMAIN_ID']; // Set this environment variable with a valid domain ID
$response = $sendingDomains->deleteSendingDomain($domainId);
// Print the response status code
var_dump($response->getStatusCode());
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}