Skip to content

Commit

Permalink
Allow using default global from
Browse files Browse the repository at this point in the history
The Laravel mail configuration defines a global from address by default, see https://github.com/laravel/laravel/blob/0993d09dc8206d0933628074036427344be16fc5/config/mail.php#L100-L114.
Thus, I think it is unnecessary and redundant to force users of this package to repeat this setting specifically for the `microsoft-graph` mailer.
  • Loading branch information
spawnia committed Dec 3, 2024
1 parent fb1e86e commit 589db34
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 68 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ First you need to add a new entry to the mail drivers array in your `config/mail
'client_id' => env('MICROSOFT_GRAPH_CLIENT_ID'),
'client_secret' => env('MICROSOFT_GRAPH_CLIENT_SECRET'),
'tenant_id' => env('MICROSOFT_GRAPH_TENANT_ID'),
'from' => [
'address' => env('MAIL_FROM_ADDRESS'),
'name' => env('MAIL_FROM_NAME'),
],
'save_to_sent_items' => env('MAIL_SAVE_TO_SENT_ITEMS', false),
],
```
Expand Down
2 changes: 0 additions & 2 deletions src/LaravelMsGraphMailServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ public function configurePackage(Package $package): void
public function boot(): void
{
Mail::extend('microsoft-graph', function (array $config): MicrosoftGraphTransport {
throw_if(blank($config['from']['address'] ?? []), new ConfigurationMissing('from.address'));

$accessTokenTtl = $config['access_token_ttl'] ?? 3000;
if (! is_int($accessTokenTtl)) {
throw new ConfigurationInvalid('access_token_ttl', $accessTokenTtl);
Expand Down
75 changes: 13 additions & 62 deletions tests/MicrosoftGraphTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
'client_id' => 'foo_client_id',
'client_secret' => 'foo_client_secret',
'tenant_id' => 'foo_tenant_id',
'from' => [
'address' => '[email protected]',
'name' => 'Taylor Otwell',
],
'save_to_sent_items' => null,
]);
Config::set('mail.default', 'microsoft-graph');
Config::set('mail.from', [
'address' => '[email protected]',
'name' => 'Taylor Otwell',
]);

Cache::set('microsoft-graph-api-access-token', 'foo_access_token', 3600);

Expand Down Expand Up @@ -105,12 +105,12 @@
'client_id' => 'foo_client_id',
'client_secret' => 'foo_client_secret',
'tenant_id' => 'foo_tenant_id',
'from' => [
'address' => '[email protected]',
'name' => 'Taylor Otwell',
],
]);
Config::set('mail.default', 'microsoft-graph');
Config::set('mail.from', [
'address' => '[email protected]',
'name' => 'Taylor Otwell',
]);

Cache::set('microsoft-graph-api-access-token', 'foo_access_token', 3600);

Expand Down Expand Up @@ -191,10 +191,6 @@
'client_id' => 'foo_client_id',
'client_secret' => 'foo_client_secret',
'tenant_id' => 'foo_tenant_id',
'from' => [
'address' => '[email protected]',
'name' => 'Taylor Otwell',
],
]);
Config::set('mail.default', 'microsoft-graph');

Expand Down Expand Up @@ -227,10 +223,6 @@
'client_id' => 'foo_client_id',
'client_secret' => 'foo_client_secret',
'tenant_id' => 'foo_tenant_id',
'from' => [
'address' => '[email protected]',
'name' => 'Taylor Otwell',
],
]);
Config::set('mail.default', 'microsoft-graph');

Expand All @@ -247,17 +239,13 @@
Config::set('mail.default', 'microsoft-graph');

expect(fn () => Mail::to('[email protected]')->send(new TestMail(false)))
->toThrow(get_class($exception), $exception->getMessage());
->toThrow($exception);
})->with([
[
[
'transport' => 'microsoft-graph',
'client_id' => 'foo_client_id',
'client_secret' => 'foo_client_secret',
'from' => [
'address' => '[email protected]',
'name' => 'Taylor Otwell',
],
],
new ConfigurationMissing('tenant_id'),
],
Expand All @@ -267,10 +255,6 @@
'tenant_id' => 123,
'client_id' => 'foo_client_id',
'client_secret' => 'foo_client_secret',
'from' => [
'address' => '[email protected]',
'name' => 'Taylor Otwell',
],
],
new ConfigurationInvalid('tenant_id', 123),
],
Expand All @@ -279,10 +263,6 @@
'transport' => 'microsoft-graph',
'tenant_id' => 'foo_tenant_id',
'client_secret' => 'foo_client_secret',
'from' => [
'address' => '[email protected]',
'name' => 'Taylor Otwell',
],
],
new ConfigurationMissing('client_id'),
],
Expand All @@ -292,10 +272,6 @@
'tenant_id' => 'foo_tenant_id',
'client_id' => '',
'client_secret' => 'foo_client_secret',
'from' => [
'address' => '[email protected]',
'name' => 'Taylor Otwell',
],
],
new ConfigurationInvalid('client_id', ''),
],
Expand All @@ -304,10 +280,6 @@
'transport' => 'microsoft-graph',
'tenant_id' => 'foo_tenant_id',
'client_id' => 'foo_client_id',
'from' => [
'address' => '[email protected]',
'name' => 'Taylor Otwell',
],
],
new ConfigurationMissing('client_secret'),
],
Expand All @@ -317,33 +289,16 @@
'tenant_id' => 'foo_tenant_id',
'client_id' => 'foo_client_id',
'client_secret' => null,
'from' => [
'address' => '[email protected]',
'name' => 'Taylor Otwell',
],
],
new ConfigurationInvalid('client_secret', null),
],
[
[
'transport' => 'microsoft-graph',
'tenant_id' => 'foo_tenant_id',
'client_id' => 'foo_client_id',
'client_secret' => 'foo_client_secret',
],
new ConfigurationMissing('from.address'),
],
[
[
'transport' => 'microsoft-graph',
'tenant_id' => 'foo_tenant_id',
'client_id' => 'foo_client_id',
'client_secret' => 'foo_client_secret',
'access_token_ttl' => false,
'from' => [
'address' => '[email protected]',
'name' => 'Taylor Otwell',
],
],
new ConfigurationInvalid('access_token_ttl', false),
],
Expand All @@ -355,10 +310,10 @@
'client_id' => 'foo_client_id',
'client_secret' => 'foo_client_secret',
'tenant_id' => 'foo_tenant_id',
'from' => [
'address' => '[email protected]',
'name' => 'Taylor Otwell',
],
]);
Config::set('mail.from', [
'address' => '[email protected]',
'name' => 'Taylor Otwell',
]);
Config::set('mail.default', 'microsoft-graph');
Config::set('filesystems.default', 'local');
Expand Down Expand Up @@ -438,10 +393,6 @@
'client_id' => 'foo_client_id',
'client_secret' => 'foo_client_secret',
'tenant_id' => 'foo_tenant_id',
'from' => [
'address' => '[email protected]',
'name' => 'Taylor Otwell',
],
]);
Config::set('mail.default', 'microsoft-graph');

Expand Down

0 comments on commit 589db34

Please sign in to comment.