forked from utopia-php/messaging
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMock.php
More file actions
59 lines (51 loc) · 1.46 KB
/
Mock.php
File metadata and controls
59 lines (51 loc) · 1.46 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
<?php
namespace Utopia\Messaging\Adapters\Email;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\PHPMailer;
use Utopia\Messaging\Adapters\Email as EmailAdapter;
use Utopia\Messaging\Messages\Email;
class Mock extends EmailAdapter
{
public function getName(): string
{
return 'Mock';
}
public function getMaxMessagesPerRequest(): int
{
// TODO: Find real value for this
return 1000;
}
/**
* {@inheritdoc}
*
* @throws Exception
* @throws \Exception
*/
protected function process(Email $message): string
{
$mail = new PHPMailer();
$mail->isSMTP();
$mail->XMailer = 'Utopia Mailer';
$mail->Host = 'maildev';
$mail->Port = 1025;
$mail->SMTPAuth = false;
$mail->Username = '';
$mail->Password = '';
$mail->SMTPSecure = false;
$mail->SMTPAutoTLS = false;
$mail->CharSet = 'UTF-8';
$mail->Subject = $message->getSubject();
$mail->Body = $message->getContent();
$mail->AltBody = \strip_tags($message->getContent());
$mail->setFrom($message->getFrom(), 'Utopia');
$mail->addReplyTo($message->getFrom(), 'Utopia');
$mail->isHTML($message->isHtml());
foreach ($message->getTo() as $to) {
$mail->addAddress($to);
}
if (! $mail->send()) {
throw new \Exception($mail->ErrorInfo);
}
return true;
}
}