• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nette / mail / 22836180643

09 Mar 2026 02:43AM UTC coverage: 77.2%. Remained the same
22836180643

push

github

dg
improved PHPDoc descriptions

386 of 500 relevant lines covered (77.2%)

0.77 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.0
/src/Mail/FallbackMailer.php
1
<?php declare(strict_types=1);
2

3
/**
4
 * This file is part of the Nette Framework (https://nette.org)
5
 * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6
 */
7

8
namespace Nette\Mail;
9

10
use Nette;
11

12

13
/**
14
 * Tries multiple mailers in sequence with retries; throws FallbackMailerException only when all attempts fail.
15
 */
16
class FallbackMailer implements Mailer
17
{
18
        /** @var array<callable(self, SendException, Mailer, Message): void> */
19
        public array $onFailure = [];
20

21

22
        public function __construct(
1✔
23
                /** @var list<Mailer> */
24
                private array $mailers,
25
                private int $retryCount = 3,
26
                /** in milliseconds */
27
                private int $retryWaitTime = 1000,
28
        ) {
29
        }
1✔
30

31

32
        /**
33
         * Sends email.
34
         * @throws FallbackMailerException
35
         */
36
        public function send(Message $mail): void
1✔
37
        {
38
                if (!$this->mailers) {
1✔
39
                        throw new Nette\InvalidArgumentException('At least one mailer must be provided.');
×
40
                }
41

42
                $failures = [];
1✔
43
                for ($i = 0; $i < $this->retryCount; $i++) {
1✔
44
                        if ($i > 0) {
1✔
45
                                usleep($this->retryWaitTime * 1000);
1✔
46
                        }
47

48
                        foreach ($this->mailers as $mailer) {
1✔
49
                                try {
50
                                        $mailer->send($mail);
1✔
51
                                        return;
1✔
52

53
                                } catch (SendException $e) {
1✔
54
                                        $failures[] = $e;
1✔
55
                                        Nette\Utils\Arrays::invoke($this->onFailure, $this, $e, $mailer, $mail);
1✔
56
                                }
57
                        }
58
                }
59

60
                $e = new FallbackMailerException('All mailers failed to send the message.');
1✔
61
                $e->failures = $failures;
1✔
62
                throw $e;
1✔
63
        }
64

65

66
        public function addMailer(Mailer $mailer): static
67
        {
68
                $this->mailers[] = $mailer;
×
69
                return $this;
×
70
        }
71
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc