-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathNetcore.php
More file actions
75 lines (65 loc) · 1.82 KB
/
Netcore.php
File metadata and controls
75 lines (65 loc) · 1.82 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
<?php
namespace Utopia\Messaging\Adapters\Email;
use Utopia\Messaging\Adapters\Email as EmailAdapter;
use Utopia\Messaging\Messages\Email;
class Netcore extends EmailAdapter
{
/**
* @param string $apiKey Your Netcore API key to authenticate with the API. (Ref: https://cpaasdocs.netcorecloud.com/docs/pepipost-api/ZG9jOjQyMTU3NjQ0-authentication)
* @param bool $isEU Whether to use the EU domain or not.
*/
public function __construct(
private string $apiKey,
private bool $isEU = false
) {
}
/**
* Get adapter name.
*
* @return string
*/
public function getName(): string
{
return 'Netcore';
}
/**
* Get adapter description.
*
* @return int
*/
public function getMaxMessagesPerRequest(): int
{
return 1000;
}
/**
* {@inheritdoc}
*
* @throws \Exception
*/
protected function process(Email $message): string
{
$usDomain = 'emailapi.netcorecloud.net';
$euDomain = 'apieu.netcorecloud.net';
$domain = $this->isEU ? $euDomain : $usDomain;
$body = [
'to' => \implode(',', $message->getTo()),
'from' => $message->getFrom(),
'subject' => $message->getSubject(),
'content' => [
'type' => $message->isHtml() ? 'html' : 'amp',
'value' => $message->getContent(),
],
];
$response = $this->request(
method: 'POST',
url: "https://$domain/v5.1/mail/send",
headers: [
'apiKey: '.base64_encode('api:'.$this->apiKey),
'Accept: application/json',
'Content-Type: application/json',
],
body: \json_encode($body)
);
return $response;
}
}