PHPackages                             ezstoritve/m365-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. ezstoritve/m365-mail

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

ezstoritve/m365-mail
====================

Laravel M365 Mail Package using the MSGraph API

v1.1.6(1y ago)09MITPHPPHP ^8.1

Since Sep 2Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/ezstoritve/m365-mail)[ Packagist](https://packagist.org/packages/ezstoritve/m365-mail)[ Docs](https://github.com/ezstoritve/m365-mail)[ RSS](/packages/ezstoritve-m365-mail/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/18cc68a6ffa3e30263b081faa7fa97c2d5d1dc12420460253c7ac5f0953b8e26/687474703a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f657a73746f72697476652f6d3336352d6d61696c2e737667)](https://packagist.org/packages/ezstoritve/m365-mail) [![Total Downloads](https://camo.githubusercontent.com/5dc41e2706f71ef3ab1984c780897bf4217f74b3abc76d639dec06fc9ff30814/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f657a73746f72697476652f6d3336352d6d61696c2e737667)](https://packagist.org/packages/ezstoritve/m365-mail) [![Donate](https://camo.githubusercontent.com/d47cdb766a100070d38a702d9c7760ccc8052063484e1478a26bcd16680d33af/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f6e6174652d70617970616c2d626c75652e737667)](https://www.paypal.me/egizaberl)

Laravel M365 Mail Package
=========================

[](#laravel-m365-mail-package)

This package provides seamless access to Microsoft M365 mail functions, allowing you to integrate email handling within your Laravel application effortlessly. It supports sending and reading emails using the Microsoft Graph API, making it easy to work with M365 mailboxes directly from your code. With this package, you can leverage features like sending, fetching emails and downloading attachments, all while securely managing authentication through your Microsoft Azure App credentials.

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

[](#installation)

You can install the package via composer:

```
// add repository to composer.json in your project - not needed anymore as package is on https://packagist.org/packages/ezstoritve/m365-mail
"repositories": [
    {
        "type": "vcs",
        "url": "https://github.com/ezstoritve/m365-mail.git"
    }
],

// install package
composer require ezstoritve/m365-mail
```

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

[](#configuration)

### Register and configure the Microsoft Azure App

[](#register-and-configure-the-microsoft-azure-app)

[Quickstart: Register an application with the Microsoft identity platform](https://learn.microsoft.com/en-us/entra/identity-platform/quickstart-register-app)

### Configuring your Laravel app

[](#configuring-your-laravel-app)

To integrate the m365-mail driver, begin by adding a new entry to the mailers array in your config/mail.php configuration file:

```
'mailers' => [
    'm365-mail' => [
        'transport' => 'm365-mail',
        'tenant_id' => env('MICROSOFT_GRAPH_TENANT_ID'),
        'client_id' => env('MICROSOFT_GRAPH_CLIENT_ID'),
        'client_secret' => env('MICROSOFT_GRAPH_CLIENT_SECRET'),
        'from_address' => env('MAIL_FROM_ADDRESS'),
        'from_name' => env('MAIL_FROM_NAME')
    ],
    ...
]
```

This entry configures the m365-mail transport and sets the required credentials and sender information.

Next, configure the following variables in your .env file to use the credentials from your Microsoft Azure App:

```
MAIL_MAILER=m365-mail
MICROSOFT_GRAPH_TENANT_ID="your_tenant_id"
MICROSOFT_GRAPH_CLIENT_ID="your_client_id"
MICROSOFT_GRAPH_CLIENT_SECRET="your_client_secret_value"
MAIL_FROM_ADDRESS="from.mail@domain.com"
MAIL_FROM_NAME="from_name"
```

These variables will be used to authenticate and send emails through the Microsoft Graph API, ensuring your Laravel application is properly connected to your Azure setup.

Usage
=====

[](#usage)

The Mail::send method and the $m object in the callback accept all standard Laravel parameters, including:

- To, Cc, Bcc: Specify recipients.
- Subject: Set the email subject.
- From: Define the sender’s email.
- ReplyTo: Set the reply-to address.
- Attachments: Attach files to the email.
- Body (text or HTML): Compose the email content.

These parameters allow for full customization of email messages within your application.

Sample code:

```
Mail::send('blade.file', [], function ($m) {
    $m->to('email.to@domain.com', 'Recipient Name')
        ->subject('Mail subject')
        ->getHeaders()->addTextHeader('X-Save', 'true'); // save an email to the sent items folder - optional
});
```

The Mail::read function accepts the following parameters:

- FolderPath (Inbox\\Folder1...): Specifies which folder in the Microsoft 365 mailbox to read from.
- Mailbox (user email): The email address of the user’s mailbox to read.
- GetFiles (true, false): Determines whether to retrieve the attachment contentBytes, allowing manual download.
- Download (true, false): Automatically downloads attachments to the specified folder.
- FilePath (e.g., public\_path('temp')): Allows you to set a custom path for downloaded files.

This code can be customized to suit your specific requirements.

Sample code:

```
$folderPath = 'Inbox\Folder1';
$mailbox = 'user.mail@domain.com';

$result = Mail::read([
    MailReadParams::FolderPath => $folderPath,
    MailReadParams::Mailbox => $mailbox,
    MailReadParams::GetFiles => false
], function ($emails) {
    $output = '';
    foreach ($emails as $email) {
        $output .= '' . htmlspecialchars($email['subject']) . '';
        $output .= 'From: ' . htmlspecialchars($email['fromName']) . ' (' . htmlspecialchars($email['from']) . ')';
        $output .= 'To: ' . htmlspecialchars(implode(', ', array_column($email['to'], 'address'))) . '';
        $output .= 'CC: ' . htmlspecialchars(implode(', ', array_column($email['cc'], 'address'))) . '';
        $output .= 'BCC: ' . htmlspecialchars(implode(', ', array_column($email['bcc'], 'address'))) . '';
        $output .= 'Date: ' . htmlspecialchars($email['receivedDateTime']) . '';
        $output .= '' . htmlspecialchars($email['bodyPreview']) . '';
        if (!empty($email['attachments'])) {
            $output .= 'Attachments:';
            foreach ($email['attachments'] as $attachment) {
                $output .= '' . htmlspecialchars($attachment['name']) . '';
                //$output .= '' . htmlspecialchars($attachment['contentBytes']) . '';
            }
            $output .= '';
        }
        $output .= '';
    }
    return $output;
});

print_r($result);
```

The Mail::read method returns an array containing the following fields:

- id: The unique identifier of the email.
- subject: The subject line of the email.
- from: The sender's email address.
- fromName: The sender's display name.
- bodyPreview: A preview of the email body.
- receivedDateTime: The timestamp when the email was received.
- hasAttachments: Boolean indicating if the email has attachments.
- to: An array of recipients, including their addresses and names.
- cc: An array of CC recipients with their addresses and names.
- bcc: An array of BCC recipients with their addresses and names.
- attachments: An array of attachments, each including the filename and contentBytes (if GetFiles is true, allowing manual download).

```
$emailDetails = [
    'id' => $email['id'],
    'subject' => $email['subject'],
    'from' => $email['from']['emailAddress']['address'],
    'fromName' => $email['from']['emailAddress']['name'],
    'bodyPreview' => $email['bodyPreview'],
    'receivedDateTime' => $email['receivedDateTime'],
    'hasAttachments' => $email['hasAttachments'],
    'to' => array_map(fn($recipient) => [
        'address' => $recipient['emailAddress']['address'],
        'name' => $recipient['emailAddress']['name'],
    ], $email['toRecipients'] ?? []),
    'cc' => array_map(fn($recipient) => [
        'address' => $recipient['emailAddress']['address'],
        'name' => $recipient['emailAddress']['name'],
    ], $email['ccRecipients'] ?? []),
    'bcc' => array_map(fn($recipient) => [
        'address' => $recipient['emailAddress']['address'],
        'name' => $recipient['emailAddress']['name'],
    ], $email['bccRecipients'] ?? []),
    'attachments' => [
        0 => [
            'name' => 'file name',
            'contentBytes' => '' // if GetFiles is set to true - you can manualy download files in Mail:read function
        ],
        ...
    ]
];
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Credits
-------

[](#credits)

- [Egi Žaberl](https://github.com/ezstoritve)
- [Egi Žaberl Home](https://www.ezstoritve.com/)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance58

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

670d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8761493?v=4)[ezstoritve](/maintainers/ezstoritve)[@ezstoritve](https://github.com/ezstoritve)

---

Top Contributors

[![ezstoritve](https://avatars.githubusercontent.com/u/8761493?v=4)](https://github.com/ezstoritve "ezstoritve (20 commits)")

---

Tags

laravelEZStoritvem365-mail

### Embed Badge

![Health badge](/badges/ezstoritve-m365-mail/health.svg)

```
[![Health](https://phpackages.com/badges/ezstoritve-m365-mail/health.svg)](https://phpackages.com/packages/ezstoritve-m365-mail)
```

###  Alternatives

[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24857.5k](/packages/vormkracht10-laravel-mails)[rickdbcn/filament-email

Log all outbound emails you send through your Filament application

130279.6k1](/packages/rickdbcn-filament-email)[backstage/mails

View logged mails and events in a beautiful Filament UI.

16120.1k](/packages/backstage-mails)[vemcogroup/laravel-sparkpost-driver

SparkPost driver to use with Laravel 6.x|7.x|8.x|9.x|10.x

431.8M1](/packages/vemcogroup-laravel-sparkpost-driver)[finity-labs/fin-mail

A powerful email template manager and composer for Filament with dynamic token replacement, template versioning, and inline email sending.

284.5k1](/packages/finity-labs-fin-mail)[slimani/filament-media-manager

A media manager plugin for Filament.

126.9k](/packages/slimani-filament-media-manager)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
