-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathElasticEmail.php
More file actions
71 lines (63 loc) · 1.77 KB
/
ElasticEmail.php
File metadata and controls
71 lines (63 loc) · 1.77 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
<?php
namespace Utopia\Messaging\Adapters\Email;
use Utopia\Messaging\Adapters\Email as EmailAdapter;
use Utopia\Messaging\Messages\Email;
class ElasticEmail extends EmailAdapter
{
/**
* @param string $apiKey Your ElasticEmail API key to authenticate with the API.
* @param string $domain Your ElasticEmail domain to send messages from.
*/
public function __construct(
private string $apiKey,
private string $domain,
private bool $isEU = false
) {
}
/**
* Get adapter name.
*
* @return string
*/
public function getName(): string
{
return 'ElasticEmail';
}
/**
* Get adapter description.
*
* @return int
*/
public function getMaxMessagesPerRequest(): int
{
return 1000;
}
/**
* {@inheritdoc}
*
* @param Email $message
* @return string
*
* @throws \Exception
*/
protected function process(Email $message): string
{
$domain = 'api.ElasticEmail.com';
$response = $this->request(
method: 'POST',
url: "https://$domain/v4/{$this->domain}/send",
headers: [
'Authorization: Basic '.base64_encode('api:'.$this->apiKey),
],
body: http_build_query([
'apiKey' => $this->apiKey,
'from' => $message->getFrom(),
'fromName' => $message->getFromName(),
'subject' => $message->getSubject(),
'bodyHtml' => $message->isHtml() ? $message->getContent() : null,
'bodyText' => $message->isHtml() ? null : $message->getContent(),
'to' => implode(',', $message->getTo()), ]),
);
return $response;
}
}