Skip to content

Commit ddc75b0

Browse files
authored
Merge pull request #10 from VETiSearch/feature/add-sandbox-mode
Add sandbox mode (and Laravel 11 support)
2 parents e784638 + 2ab0031 commit ddc75b0

File tree

5 files changed

+32
-2
lines changed

5 files changed

+32
-2
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ MAIL_FROM_ADDRESS=
2626
MAIL_FROM_NAME=
2727
MAILJET_SMS_SENDER=
2828
MAILJET_DRY=true|false
29+
MAILJET_SANDBOX=true|false
2930
```
3031

3132
Make sure that MAIL_FROM_ADDRESS is an authenticated email on Mailjet, otherwise your emails will not be sent by the Mailjet API.
@@ -34,6 +35,8 @@ MAILJET_SMS_SENDER should be between 3 and 11 characters in length, only alphanu
3435

3536
When the dry mode is enabled, Mailjet API isn't called.
3637

38+
When the sandbox mode is enabled, Mailjet API is called but the mail is not send by Mailjet (requires Send API v3.1).
39+
3740
You can publish the configuration file with:
3841

3942
```shell

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
],
2424
"require": {
2525
"php": "^8.0",
26-
"illuminate/support": "^9|^10",
27-
"illuminate/database": "^9|^10",
26+
"illuminate/support": "^9|^10|^11|^12",
27+
"illuminate/database": "^9|^10|^11|^12",
2828
"mailjet/mailjet-apiv3-php": "^1.5"
2929
},
3030
"require-dev": {

config/mailjet.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
],
1111
'smsFrom' => env('MAILJET_SMS_SENDER'),
1212
'dry' => (bool) env('MAILJET_DRY', false),
13+
'sandbox' => (bool) env('MAILJET_SANDBOX', false),
1314
'options' => [
1415
'version' => 'v3.1',
1516
],

src/MailjetEmailMessage.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ class MailjetEmailMessage
3030

3131
public array $attachments = [];
3232

33+
public bool $sandboxMode = false;
34+
35+
public function __construct()
36+
{
37+
$this->sandboxMode = (bool) config('mailjet.sandbox', false);
38+
}
39+
3340
public function templateId(int $templateId): static
3441
{
3542
$this->templateId = $templateId;
@@ -177,6 +184,7 @@ public function toArray(): array
177184
'Messages' => [
178185
$messagesData,
179186
],
187+
'SandboxMode' => $this->sandboxMode,
180188
];
181189
}
182190
}

tests/MailjetEmailMessageTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
use YieldStudio\LaravelMailjetNotifier\MailjetEmailMessage;
4+
5+
test('SandboxMode is default false', function (): void {
6+
$message = (new MailjetEmailMessage())->templateId(123);
7+
8+
expect($message->toArray()['SandboxMode'])->toBe(false);
9+
});
10+
11+
test('SandboxMode is true when config is set', function (): void {
12+
// Set sandbox value in config to true
13+
config(['mailjet.sandbox' => true]);
14+
15+
$message = (new MailjetEmailMessage())->templateId(123);
16+
17+
expect($message->toArray()['SandboxMode'])->toBe(true);
18+
});

0 commit comments

Comments
 (0)