1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Shopware\Core\Content\Mail\Service; |
4
|
|
|
|
5
|
|
|
use Shopware\Core\Content\MailTemplate\Exception\MailTransportFailedException; |
6
|
|
|
use Shopware\Core\Framework\Feature; |
7
|
|
|
use Shopware\Core\Framework\Feature\Exception\FeatureNotActiveException; |
8
|
|
|
use Shopware\Core\Framework\Plugin\Exception\DecorationPatternException; |
9
|
|
|
use Shopware\Core\System\SystemConfig\SystemConfigService; |
10
|
|
|
use Symfony\Component\Mailer\Envelope; |
11
|
|
|
use Symfony\Component\Mailer\Mailer; |
12
|
|
|
use Symfony\Component\Mime\Email; |
13
|
|
|
|
14
|
|
|
class MailSender extends AbstractMailSender |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var Mailer |
18
|
|
|
*/ |
19
|
|
|
private $mailer; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var SystemConfigService |
23
|
|
|
*/ |
24
|
|
|
private $configService; |
25
|
|
|
|
26
|
|
|
public function __construct(Mailer $mailer, SystemConfigService $configService) |
27
|
|
|
{ |
28
|
|
|
if (!Feature::isActive('FEATURE_NEXT_12246')) { |
29
|
|
|
throw new FeatureNotActiveException('FEATURE_NEXT_12246'); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
$this->mailer = $mailer; |
33
|
|
|
$this->configService = $configService; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function getDecorated(): AbstractMailSender |
37
|
|
|
{ |
38
|
|
|
throw new DecorationPatternException(self::class); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @throws MailTransportFailedException |
43
|
|
|
*/ |
44
|
|
|
public function send(Email $email, ?Envelope $envelope = null): void |
45
|
|
|
{ |
46
|
|
|
$failedRecipients = []; |
47
|
|
|
|
48
|
|
|
$disabled = $this->configService->get('core.mailerSettings.disableDelivery'); |
49
|
|
|
if ($disabled) { |
50
|
|
|
return; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
$deliveryAddress = $this->configService->getString('core.mailerSettings.deliveryAddress'); |
54
|
|
|
if ($deliveryAddress !== '') { |
55
|
|
|
$email->addBcc($deliveryAddress); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
try { |
59
|
|
|
$this->mailer->send($email, $envelope); |
60
|
|
|
} catch (\Throwable $e) { |
61
|
|
|
throw new MailTransportFailedException($failedRecipients, $e); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|