Skip to content

Commit ba8f300

Browse files
committed
wip
1 parent dd02119 commit ba8f300

15 files changed

+328
-52
lines changed

README.md

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
1-
# This is my package laravel-msgraph-mail
1+
# Laravel Microsoft Graph Mail Driver Package
22

33
[![Latest Version on Packagist](https://img.shields.io/packagist/v/innoge/laravel-msgraph-mail.svg?style=flat-square)](https://packagist.org/packages/innoge/laravel-msgraph-mail)
44
[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/innoge/laravel-msgraph-mail/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/innoge/laravel-msgraph-mail/actions?query=workflow%3Arun-tests+branch%3Amain)
55
[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/innoge/laravel-msgraph-mail/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/innoge/laravel-msgraph-mail/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
66
[![Total Downloads](https://img.shields.io/packagist/dt/innoge/laravel-msgraph-mail.svg?style=flat-square)](https://packagist.org/packages/innoge/laravel-msgraph-mail)
77

8-
This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.
9-
10-
## Support us
11-
12-
[<img src="https://github-ads.s3.eu-central-1.amazonaws.com/laravel-msgraph-mail.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/laravel-msgraph-mail)
13-
14-
We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).
15-
16-
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).
8+
This package provides a Microsoft Graph mail driver for Laravel. It is an alternative when you don't want to use the
9+
deprecated and unsecure Basic Auth SMTP driver with Microsoft Office 365.
1710

1811
## Installation
1912

@@ -23,7 +16,22 @@ You can install the package via composer:
2316
composer require innoge/laravel-msgraph-mail
2417
```
2518

26-
First you need to add a new entry to the mail drivers array in your config/mail.php configuration file:
19+
## Configuration
20+
21+
### Register the Azure App
22+
23+
You need to register an Azure App in your Azure AD tenant. You can do this by following the steps in
24+
the [Microsoft Graph documentation](https://docs.microsoft.com/en-us/graph/auth-register-app-v2).
25+
26+
After creating the App you have to add the following permissions to the App:
27+
Mail.Send (Application permission) you will find it under the "Microsoft Graph" section.
28+
29+
Now you have to Grant Admin Consent for the App. You can do this by following the steps in
30+
the [Microsoft Graph documentation](https://docs.microsoft.com/en-us/graph/auth-v2-service#3-get-administrator-consent).
31+
32+
### Configuring your Laravel app
33+
34+
First you need to add a new entry to the mail drivers array in your `config/mail.php` configuration file:
2735

2836
```php
2937
'microsoft-graph' => [
@@ -37,6 +45,16 @@ First you need to add a new entry to the mail drivers array in your config/mail.
3745
],
3846
],
3947
```
48+
49+
For the `client_id`, `client_secret` and `tenant_id` you need to use the values from the Azure App you created in the
50+
previous step.
51+
52+
Now you can switch your default mail driver to the new `microsoft-graph` driver by setting the env variable:
53+
54+
```dotenv
55+
MAIL_MAILER=microsoft-graph
56+
```
57+
4058
## Testing
4159

4260
```bash

phpstan-baseline.neon

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: "#^Parameter \\#1 \\$message of static method Symfony\\\\Component\\\\Mime\\\\MessageConverter\\:\\:toEmail\\(\\) expects Symfony\\\\Component\\\\Mime\\\\Message, Symfony\\\\Component\\\\Mime\\\\RawMessage given\\.$#"
5+
count: 1
6+
path: src/MicrosoftGraphTransport.php

phpstan.neon.dist

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ includes:
22
- phpstan-baseline.neon
33

44
parameters:
5-
level: 4
5+
level: 8
66
paths:
77
- src
8-
- config
9-
- database
108
tmpDir: build/phpstan
119
checkOctaneCompatibility: true
1210
checkModelProperties: true
1311
checkMissingIterableValueType: false
12+
checkGenericClassInNonGenericObjectType: false
1413

src/Dto/MicrosoftGraphMail.php

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/Exceptions/ConfigurationMissing.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,21 @@ class ConfigurationMissing extends Exception
88
{
99
public static function tenantId(): self
1010
{
11-
return new static('The tenant id is missing from the configuration file.');
11+
return new self('The tenant id is missing from the configuration file.');
1212
}
1313

1414
public static function clientId(): self
1515
{
16-
return new static('The client id is missing from the configuration file.');
16+
return new self('The client id is missing from the configuration file.');
1717
}
1818

1919
public static function clientSecret(): self
2020
{
21-
return new static('The client secret is missing from the configuration file.');
21+
return new self('The client secret is missing from the configuration file.');
22+
}
23+
24+
public static function fromAddress(): self
25+
{
26+
return new self('The mail from address is missing from the configuration file.');
2227
}
2328
}

src/LaravelMsGraphMailServiceProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public function boot(): void
3939
});
4040

4141
Mail::extend('microsoft-graph', function (array $config) {
42+
throw_unless(filled($config['from']['address'] ?? []), ConfigurationMissing::fromAddress());
43+
4244
return new MicrosoftGraphTransport(
4345
app()->make(MicrosoftGraphApiService::class),
4446
$config['from']['address']

src/MicrosoftGraphTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function __construct(protected MicrosoftGraphApiService $microsoftGraphAp
2323

2424
public function __toString(): string
2525
{
26-
return sprintf('microsoft+graph+api://%s', $this->getEndpoint());
26+
return 'microsoft+graph+api://';
2727
}
2828

2929
/**

tests/ExampleTest.php

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)