PHPackages                             holmessohe/graph-mail - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. holmessohe/graph-mail

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

holmessohe/graph-mail
=====================

Send emails via Microsoft Graph API for laravel

v1.0.0(2mo ago)09MITPHPPHP ^8.0

Since Apr 9Pushed 2mo agoCompare

[ Source](https://github.com/hstkbj/holmessohe-graph-mail)[ Packagist](https://packagist.org/packages/holmessohe/graph-mail)[ RSS](/packages/holmessohe-graph-mail/feed)WikiDiscussions main Synced 2w ago

READMEChangelogDependencies (4)Versions (2)Used By (0)

holmessohe/graph-mail
=====================

[](#holmessohegraph-mail)

Package Laravel pour envoyer des emails via **Microsoft Graph API** (Office 365 / Azure AD).

---

Prérequis
---------

[](#prérequis)

- PHP 8.0+
- Laravel 9, 10 ou 11
- Un compte Microsoft Azure avec une application enregistrée

---

Installation
------------

[](#installation)

```
composer require holmessohe/graph-mail
```

---

Configuration
-------------

[](#configuration)

### 1. Publier la configuration

[](#1-publier-la-configuration)

```
php artisan vendor:publish --tag=graph-mail-config
```

Cela va créer le fichier `config/graph-mail.php` dans ton projet.

### 2. Ajouter les variables dans `.env`

[](#2-ajouter-les-variables-dans-env)

```
MICROSOFT_TENANT_ID=ton-tenant-id
MICROSOFT_CLIENT_ID=ton-client-id
MICROSOFT_CLIENT_SECRET=ton-client-secret
MICROSOFT_SENDER_EMAIL=expediteur@tondomaine.com
```

### 3. Où trouver ces valeurs ?

[](#3-où-trouver-ces-valeurs-)

- Va sur [portal.azure.com](https://portal.azure.com)
- **App registrations** → sélectionne ton application
- `MICROSOFT_TENANT_ID` → **Directory (tenant) ID**
- `MICROSOFT_CLIENT_ID` → **Application (client) ID**
- `MICROSOFT_CLIENT_SECRET` → **Certificates &amp; secrets** → New client secret
- `MICROSOFT_SENDER_EMAIL` → L'adresse email qui va envoyer les mails

---

Utilisation
-----------

[](#utilisation)

### Envoi simple

[](#envoi-simple)

```
use HolmesSohe\GraphMail\GraphMailService;

$graph = new GraphMailService();

$graph->sendMail(
    to: 'destinataire@example.com',
    subject: 'Bonjour',
    htmlBody: 'Bonjour !Ceci est un email de test.'
);
```

### Envoi avec une vue Blade

[](#envoi-avec-une-vue-blade)

```
use HolmesSohe\GraphMail\GraphMailService;
use Illuminate\Support\Facades\View;

$graph = new GraphMailService();

$html = View::make('emails.mon-template', [
    'nom'     => 'Holmès',
    'message' => 'Votre demande a bien été reçue.'
])->render();

$graph->sendMail(
    to: 'destinataire@example.com',
    subject: 'Confirmation',
    htmlBody: $html
);
```

### Envoi avec pièce jointe (PDF)

[](#envoi-avec-pièce-jointe-pdf)

```
use HolmesSohe\GraphMail\GraphMailService;

$graph = new GraphMailService();

$graph->sendMail(
    to: 'destinataire@example.com',
    subject: 'Votre facture',
    htmlBody: 'Veuillez trouver votre facture en pièce jointe.',
    attachmentPath: storage_path('app/factures/facture-001.pdf'),
    attachmentName: 'facture-001.pdf'
);
```

> ⚠️ La pièce jointe doit faire **moins de 3 Mo**.

### Envoi à plusieurs destinataires

[](#envoi-à-plusieurs-destinataires)

```
use HolmesSohe\GraphMail\GraphMailService;

$graph = new GraphMailService();

$destinataires = [
    'user1@example.com',
    'user2@example.com',
    'user3@example.com',
];

foreach ($destinataires as $email) {
    $graph->sendMail(
        to: $email,
        subject: 'Notification',
        htmlBody: 'Bonjour !'
    );
}
```

### Utilisation dans un Controller

[](#utilisation-dans-un-controller)

```
