4
4
5
5
use Exception ;
6
6
use GuzzleHttp \Exception \GuzzleException ;
7
+ use http \Env ;
8
+ use Symfony \Component \Mailer \Envelope ;
7
9
use Symfony \Component \Mailer \Exception \TransportException ;
8
10
use Symfony \Component \Mailer \Transport \AbstractTransport ;
9
11
use Lundalogik \NewsletterDriver \Newsletter \AttachmentModel ;
@@ -39,9 +41,12 @@ public function __construct(TransactionMail $api)
39
41
protected function doSend (SentMessage $ message ): void
40
42
{
41
43
try {
42
- $ this ->api ->sendBatch (
43
- $ this ->getSendTransactionMailBatchArgs ($ message )
44
- );
44
+ $ originalMessage = $ message ->getOriginalMessage ();
45
+ if ($ originalMessage instanceof Email) {
46
+ $ this ->api ->sendBatch (
47
+ $ this ->getSendTransactionMailBatchArgs ($ message ->getEnvelope (), $ originalMessage )
48
+ );
49
+ }
45
50
} catch (GuzzleException $ e ) {
46
51
throw new TransportException (
47
52
'Request to Newsletter API failed. ' ,
@@ -55,34 +60,29 @@ protected function doSend(SentMessage $message): void
55
60
/**
56
61
* Get the SendTransactionMailBatchArgs from the message
57
62
*
58
- * @param SentMessage $message
59
- * @return SendTransactionMailBatchArgs|null
63
+ * @param Envelope $envelope
64
+ * @param Email $message
65
+ * @return SendTransactionMailBatchArgs
60
66
*/
61
- protected function getSendTransactionMailBatchArgs (SentMessage $ message ): ? SendTransactionMailBatchArgs
67
+ protected function getSendTransactionMailBatchArgs (Envelope $ envelope , Email $ message ): SendTransactionMailBatchArgs
62
68
{
63
69
$ sendTransactionMailArgs = [];
64
70
65
- $ envelope = $ message ->getEnvelope ();
66
-
67
71
$ fromEmail = $ envelope ->getSender ()->getAddress ();
68
72
$ fromName = $ envelope ->getSender ()->getName ();
69
73
70
- $ originalMessage = $ message ->getOriginalMessage ();
71
-
72
- if ($ originalMessage instanceof Email) {
73
- foreach ($ envelope ->getRecipients () as $ index => $ to ) {
74
- $ sendTransactionMailArgs [] = (new SendTransactionMailArgs ())
75
- ->to ($ to ->getAddress (), $ to ->getName ())
76
- ->from ($ fromEmail , $ fromName )
77
- ->subject ($ originalMessage ->getSubject ())
78
- ->htmlContent ($ originalMessage ->getHtmlBody ());
79
- }
80
-
81
- return new SendTransactionMailBatchArgs (
82
- $ sendTransactionMailArgs ,
83
- $ this ->buildAttachmentModels ($ originalMessage )
84
- );
74
+ foreach ($ envelope ->getRecipients () as $ index => $ to ) {
75
+ $ sendTransactionMailArgs [] = (new SendTransactionMailArgs ())
76
+ ->to ($ to ->getAddress (), $ to ->getName ())
77
+ ->from ($ fromEmail , $ fromName )
78
+ ->subject ($ message ->getSubject ())
79
+ ->htmlContent ($ message ->getHtmlBody ());
85
80
}
81
+
82
+ return new SendTransactionMailBatchArgs (
83
+ $ sendTransactionMailArgs ,
84
+ $ this ->buildAttachmentModels ($ message )
85
+ );
86
86
}
87
87
88
88
/**
0 commit comments