Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d60f400

Browse files
mdawartnicolas-grekas
authored andcommitted
[Mailer] Add option to enable Sandbox via dsn option sandbox=true
1 parent bef46c8 commit d60f400

File tree

5 files changed

+65
-3
lines changed

5 files changed

+65
-3
lines changed

src/Symfony/Component/Mailer/Bridge/Mailjet/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
6.3
5+
---
6+
7+
* Add sandbox option
8+
49
5.2.0
510
-----
611

src/Symfony/Component/Mailer/Bridge/Mailjet/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Configuration examples:
88
```dotenv
99
# API
1010
MAILER_DSN=mailjet+api://$PUBLIC_KEY:$PRIVATE_KEY@default
11+
MAILER_DSN=mailjet+api://$PUBLIC_KEY:$PRIVATE_KEY@default?sandbox=true
1112
# SMTP
1213
MAILER_DSN=mailjet+smtp://$PUBLIC_KEY:$PRIVATE_KEY@default
1314
```

src/Symfony/Component/Mailer/Bridge/Mailjet/Tests/Transport/MailjetApiTransportTest.php

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,6 @@ public function testHeaderToMessage()
318318

319319
$transport = new MailjetApiTransport(self::USER, self::PASSWORD);
320320
$method = new \ReflectionMethod(MailjetApiTransport::class, 'getPayload');
321-
$method->setAccessible(true);
322321
self::assertSame(
323322
[
324323
'Messages' => [
@@ -364,6 +363,59 @@ public function testHeaderToMessage()
364363
'TrackOpen' => 'account_default',
365364
],
366365
],
366+
'SandBoxMode' => false,
367+
],
368+
$method->invoke($transport, $email, $envelope)
369+
);
370+
371+
$transport = new MailjetApiTransport(self::USER, self::PASSWORD, sandbox: true);
372+
$method = new \ReflectionMethod(MailjetApiTransport::class, 'getPayload');
373+
self::assertSame(
374+
[
375+
'Messages' => [
376+
[
377+
'From' => [
378+
'Email' => '[email protected]',
379+
'Name' => 'Foo',
380+
],
381+
'To' => [
382+
[
383+
'Email' => '[email protected]',
384+
'Name' => '',
385+
],
386+
],
387+
'Subject' => 'Sending email to mailjet API',
388+
'Attachments' => [],
389+
'InlinedAttachments' => [],
390+
'ReplyTo' => [
391+
'Email' => '[email protected]',
392+
'Name' => 'Qux',
393+
],
394+
'Headers' => [
395+
'X-authorized-header' => 'authorized',
396+
],
397+
'TemplateLanguage' => true,
398+
'TemplateID' => 12345,
399+
'TemplateErrorReporting' => [
400+
'Email' => '[email protected]',
401+
'Name' => 'Error Email',
402+
],
403+
'TemplateErrorDeliver' => true,
404+
'Variables' => [
405+
'varname1' => 'value1',
406+
'varname2' => 'value2',
407+
'varname3' => 'value3',
408+
],
409+
'CustomID' => 'CustomValue',
410+
'EventPayload' => 'Eticket,1234,row,15,seat,B',
411+
'CustomCampaign' => 'SendAPI_campaign',
412+
'DeduplicateCampaign' => true,
413+
'Priority' => 2,
414+
'TrackClick' => 'account_default',
415+
'TrackOpen' => 'account_default',
416+
],
417+
],
418+
'SandBoxMode' => true,
367419
],
368420
$method->invoke($transport, $email, $envelope)
369421
);

src/Symfony/Component/Mailer/Bridge/Mailjet/Transport/MailjetApiTransport.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,13 @@ class MailjetApiTransport extends AbstractApiTransport
5353

5454
private string $privateKey;
5555
private string $publicKey;
56+
private bool $sandbox;
5657

57-
public function __construct(string $publicKey, string $privateKey, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null, LoggerInterface $logger = null)
58+
public function __construct(string $publicKey, string $privateKey, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null, LoggerInterface $logger = null, bool $sandbox = false)
5859
{
5960
$this->publicKey = $publicKey;
6061
$this->privateKey = $privateKey;
62+
$this->sandbox = $sandbox;
6163

6264
parent::__construct($client, $dispatcher, $logger);
6365
}
@@ -153,6 +155,7 @@ private function getPayload(Email $email, Envelope $envelope): array
153155

154156
return [
155157
'Messages' => [$message],
158+
'SandBoxMode' => $this->sandbox,
156159
];
157160
}
158161

src/Symfony/Component/Mailer/Bridge/Mailjet/Transport/MailjetTransportFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ public function create(Dsn $dsn): TransportInterface
2424
$user = $this->getUser($dsn);
2525
$password = $this->getPassword($dsn);
2626
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
27+
$sandbox = filter_var($dsn->getOption('sandbox', false), \FILTER_VALIDATE_BOOL);
2728

2829
if ('mailjet+api' === $scheme) {
29-
return (new MailjetApiTransport($user, $password, $this->client, $this->dispatcher, $this->logger))->setHost($host);
30+
return (new MailjetApiTransport($user, $password, $this->client, $this->dispatcher, $this->logger, $sandbox))->setHost($host);
3031
}
3132

3233
if (\in_array($scheme, ['mailjet+smtp', 'mailjet+smtps', 'mailjet'])) {

0 commit comments

Comments
 (0)