-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathMock.php
More file actions
66 lines (57 loc) · 1.84 KB
/
Copy pathMock.php
File metadata and controls
66 lines (57 loc) · 1.84 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
<?php
namespace Utopia\Messaging\Adapter\Email;
use PHPMailer\PHPMailer\PHPMailer;
use Utopia\Messaging\Adapter\Email as EmailAdapter;
use Utopia\Messaging\Messages\Email as EmailMessage;
use Utopia\Messaging\Response;
class Mock extends EmailAdapter
{
protected const NAME = 'Mock';
public function getName(): string
{
return static::NAME;
}
public function getMaxMessagesPerRequest(): int
{
// TODO: Find real value for this
return 1000;
}
/**
* {@inheritdoc}
*/
protected function process(EmailMessage $message): array
{
$response = new Response($this->getType());
$mail = new PHPMailer();
$mail->isSMTP();
$mail->XMailer = 'Utopia Mailer';
$mail->Host = 'maildev';
$mail->Port = 1025;
$mail->SMTPAuth = false;
$mail->Username = '';
$mail->Password = '';
$mail->SMTPSecure = '';
$mail->SMTPAutoTLS = false;
$mail->CharSet = 'UTF-8';
$mail->Subject = $message->getSubject();
$mail->Body = $message->getContent();
$mail->AltBody = \strip_tags($message->getContent());
$mail->setFrom($message->getFromEmail(), $message->getFromName());
$mail->addReplyTo($message->getReplyToEmail(), $message->getReplyToName());
$mail->isHTML($message->isHtml());
foreach ($message->getTo() as $to) {
$mail->addAddress($to);
}
if (!$mail->send()) {
foreach ($message->getTo() as $to) {
$response->addResultForRecipient($to, $mail->ErrorInfo);
}
} else {
$response->setDeliveredTo(\count($message->getTo()));
foreach ($message->getTo() as $to) {
$response->addResultForRecipient($to);
}
}
return $response->toArray();
}
}