PHPackages                             seydou91/o365\_smtp - 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. seydou91/o365\_smtp

ActiveDrupal-module[Mail &amp; Notifications](/categories/mail)

seydou91/o365\_smtp
===================

Sends emails via Office 365 SMTP using OAuth2 authentication.

10.1.0(1mo ago)00GPL-2.0-or-laterPHPPHP &gt;=8.1

Since Apr 17Pushed 1mo agoCompare

[ Source](https://github.com/seydou91/o365_smtp)[ Packagist](https://packagist.org/packages/seydou91/o365_smtp)[ RSS](/packages/seydou91-o365-smtp/feed)WikiDiscussions 10.x-1.x Synced 1w ago

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

Office 365 SMTP OAuth2
======================

[](#office-365-smtp-oauth2)

[![License](https://camo.githubusercontent.com/43a510dd0989747b1c3997cb691eaef0adc0f48c2ba392da31b012ef9030bf23/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d47504c2d2d322e302d2d6f722d2d6c617465722d626c75652e737667)](https://www.gnu.org/licenses/old-licenses/gpl-2.0.txt)[![Drupal compatibility](https://camo.githubusercontent.com/a325be3b07f62285f443faa0baa8f1a2c746c28808b1edae7d048fb8304c81a6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f44727570616c2d313025323025374325323031312d626c61636b2e737667)](https://www.drupal.org/project/o365_smtp)[![GitHub release](https://camo.githubusercontent.com/7b5b8055be7128834f0105ef89bff2e10451a660021eb5b937f74a0b1f0046e2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f736579646f7539312f6f3336355f736d7470)](https://github.com/seydou91/o365_smtp/releases)

Sends emails via Office 365 / Microsoft 365 using OAuth2 authentication. This module provides a complete solution for sending emails from your Drupal site through Office 365's SMTP servers without needing to store credentials in plain text.

Features
--------

[](#features)

- **OAuth2 Authentication**: Secure authentication using Microsoft OAuth2 (no plain text passwords)
- **Automatic Token Refresh**: Tokens are automatically refreshed before expiration
- **File Attachments**: Full support for sending emails with file attachments (MIME multipart)
- **Entity Configuration**: Settings managed via Drupal's configuration system
- **Test Form**: Built-in form to test email sending

Requirements
------------

[](#requirements)

- A Microsoft Entra ID (Azure AD) application registered in the Azure portal
- The application must have **Mail.Send** permission for Microsoft Graph API
- A client secret or X.509 certificate configured in Azure AD
- PHP 8.1+ with OpenSSL extension
- Drupal 10 or 11

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

[](#installation)

### Using Composer (Recommended)

[](#using-composer-recommended)

```
composer require seydou91/o365_smtp
```

### Enable the Module

[](#enable-the-module)

```
drush en o365_smtp
```

Or via the admin UI:

1. Go to **Extend** (`/admin/modules`)
2. Find "Office 365 SMTP OAuth2" and enable it

Azure AD / Microsoft Entra ID Setup
-----------------------------------

[](#azure-ad--microsoft-entra-id-setup)

### Step 1: Register an Application

[](#step-1-register-an-application)

1. Go to [Microsoft Azure Portal](https://portal.azure.com/) &gt; **Microsoft Entra ID** (formerly Azure Active Directory)
2. Go to **App registrations** &gt; **New registration**
3. Enter a name (e.g., "Drupal SMTP")
4. Set redirect URI: `https://your-domain.com/phpmailer_oauth2/aad-callback`
5. Click **Register**
6. Copy the **Application (client) ID** and **Directory (tenant) ID**

### Step 2: Create Client Secret

[](#step-2-create-client-secret)

1. In your app registration, go to **Certificates &amp; secrets**
2. Click **New client secret**
3. Add a description and select expiration
4. Click **Add**
5. **Copy the secret value immediately** (it won't be shown again)

### Step 3: Configure API Permissions

[](#step-3-configure-api-permissions)

1. Go to **API permissions**
2. Click **Add a permission**
3. Select **Microsoft Graph** &gt; **Application permissions**
4. Check **Mail.Send**
5. Click **Add permissions**
6. Click **Grant admin consent** for your organization

### Step 4: Note Your Credentials

[](#step-4-note-your-credentials)

You will need:

- **Application (client) ID** (e.g., `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`)
- **Client secret value** (the secret you just created)
- **Directory (tenant) ID** (e.g., `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`)

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

[](#configuration)

### Step 1: Configure the Module

[](#step-1-configure-the-module)

1. Go to **Configuration** &gt; **System** &gt; **Office 365 SMTP Settings** (`/admin/config/system/o365_smtp`)
2. Fill in the form:
    - **Application (Client) ID**: Your Azure AD client ID
    - **Client Secret Value**: Your Azure AD client secret
    - **Directory (Tenant) ID**: Your Azure AD tenant ID
    - **From Email Address**: The email address to send from (must match an authorized user)
    - **From Name** (optional): Display name for the sender
3. Click **Save configuration**

### Step 2: Authorize with Microsoft

[](#step-2-authorize-with-microsoft)

Click the **Authorize with Office 365** button to complete the OAuth2 flow.

### Step 3: Set as Default Mail System (Optional)

[](#step-3-set-as-default-mail-system-optional)

To use this module for all site emails:

1. Go to **Configuration** &gt; **System** &gt; **Mail system** (`/admin/config/system/mail`)
2. Set the "Default system" to "Office 365 SMTP"

Usage
-----

[](#usage)

### Sending Test Emails

[](#sending-test-emails)

Use the built-in test form at `/admin/config/system/o365_smtp/test`

### Sending Emails with Attachments

[](#sending-emails-with-attachments)

You can send emails with attachments programmatically:

```
use Drupal\Core\Mail\MailManagerInterface;

$mail_manager = \Drupal::service('plugin.manager.mail');

// Prepare attachments.
$params['attachments'] = [
  [
    'filepath' => '/path/to/document.pdf',
    'filename' => 'document.pdf',
    'filemime' => 'application/pdf',
  ],
];

$module = 'o365_smtp';
$key = 'custom_email';
$to = 'recipient@example.com';
$langcode = \Drupal::languageManager()->getDefaultLanguage()->getId();

$result = $mail_manager->mail($module, $key, $to, $langcode, $params);
```

Troubleshooting
---------------

[](#troubleshooting)

### "SMTP Error: 500 5.3.3 Unrecognized command"

[](#smtp-error-500-533-unrecognized-command)

This usually indicates a protocol error. Make sure:

- Your PHP has the OpenSSL extension enabled
- Your Azure AD application has **Mail.Send** permissions
- Admin consent was granted for the permissions

### Authentication Failed

[](#authentication-failed)

- Verify your Client ID and Client Secret are correct
- Make sure the "From Email" matches an account authorized to send emails
- Re-authorize if needed by clicking the authorization link again

### Connection Refused

[](#connection-refused)

- Check that your server can connect to `smtp.office365.com:587`
- Verify firewall rules allow outbound SMTP connections

Frequently Asked Questions
--------------------------

[](#frequently-asked-questions)

### Does this work with Gmail or other providers?

[](#does-this-work-with-gmail-or-other-providers)

This module is specifically designed for Microsoft Office 365 / Microsoft 365. It uses Microsoft's OAuth2 endpoints and SMTP servers.

### Can I use this with Drupal 9?

[](#can-i-use-this-with-drupal-9)

For Drupal 9 support, use the `8.x-1.x` branch. Note that official support may be dropped in future versions.

### How do I upgrade the module?

[](#how-do-i-upgrade-the-module)

```
composer update seydou91/o365_smtp
```

Then clear Drupal's cache:

```
drush cr
```

Security Considerations
-----------------------

[](#security-considerations)

- **No passwords stored**: OAuth2 tokens are used instead of passwords
- **Tokens stored securely**: Tokens are stored in Drupal's State API
- **Automatic refresh**: Tokens are refreshed automatically before expiration

License
-------

[](#license)

This project is licensed under the [GNU General Public License, version 2 or later](https://www.gnu.org/licenses/old-licenses/gpl-2.0.txt).

Support
-------

[](#support)

- Report issues at: [https://www.drupal.org/project/issues/o365\_smtp](https://www.drupal.org/project/issues/o365_smtp)
- GitHub issue tracker: [https://github.com/seydou91/o365\_smtp/issues](https://github.com/seydou91/o365_smtp/issues)

Maintainers
-----------

[](#maintainers)

- [seydou91](https://www.drupal.org/u/seydou91) - Original author

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance90

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity42

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

53d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b55b5e0788449d875f4b4810ff942d1c4ba77330083ea8770ff5bef329ec6328?d=identicon)[seydou91](/maintainers/seydou91)

---

Top Contributors

[![seydou91](https://avatars.githubusercontent.com/u/19875950?v=4)](https://github.com/seydou91 "seydou91 (1 commits)")

### Embed Badge

![Health badge](/badges/seydou91-o365-smtp/health.svg)

```
[![Health](https://phpackages.com/badges/seydou91-o365-smtp/health.svg)](https://phpackages.com/packages/seydou91-o365-smtp)
```

###  Alternatives

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.3k532.1M2.5k](/packages/aws-aws-sdk-php)[neuron-core/neuron-ai

The PHP Agentic Framework.

1.9k496.1k32](/packages/neuron-core-neuron-ai)[drupal/core-recommended

Locked core dependencies; require this project INSTEAD OF drupal/core.

6941.5M395](/packages/drupal-core-recommended)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3751.2M45](/packages/tencentcloud-tencentcloud-sdk-php)[tempest/framework

The PHP framework that gets out of your way.

2.2k31.1k11](/packages/tempest-framework)[guanguans/notify

Push notification SDK(AnPush、Bark、Chanify、DingTalk、Discord、Gitter、GoogleChat、IGot、Lark、Mattermost、MicrosoftTeams、NotifyX、NowPush、Ntfy、Push、Pushback、PushBullet、PushDeer、PushMe、Pushover、PushPlus、QQ、RocketChat、ServerChan、ShowdocPush、SimplePush、Slack、Telegram、WeWork、WPush、XiZhi、YiFengChuanHua、ZohoCliq、ZohoCliqWebHook、Zulip).

687111.2k8](/packages/guanguans-notify)

PHPackages © 2026

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