PHPackages                             orange-soft/laravel-gmail-mailer - 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. orange-soft/laravel-gmail-mailer

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

orange-soft/laravel-gmail-mailer
================================

Laravel mail transport using Gmail API with OAuth2 authentication

v1.0.3(6mo ago)047MITPHPPHP ^8.0.2

Since Dec 24Pushed 6mo agoCompare

[ Source](https://github.com/orange-soft/laravel-gmail-mailer)[ Packagist](https://packagist.org/packages/orange-soft/laravel-gmail-mailer)[ Docs](https://github.com/orange-soft/laravel-gmail-mailer)[ RSS](/packages/orange-soft-laravel-gmail-mailer/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (7)Versions (5)Used By (0)

Laravel Gmail Mailer
====================

[](#laravel-gmail-mailer)

A Laravel mail transport using Gmail API with OAuth2 authentication. This package provides a secure alternative to SMTP for sending emails through Gmail.

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

[](#requirements)

- PHP 8.0.2+
- Laravel 9.0, 10.0, 11.0, or 12.0
- A Google Cloud project with Gmail API enabled

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

[](#installation)

Install the package via Composer:

```
composer require orange-soft/laravel-gmail-mailer
```

The package will auto-register its service provider.

### Publish Configuration

[](#publish-configuration)

```
php artisan vendor:publish --tag=gmail-mailer-config
```

Google Cloud Setup
------------------

[](#google-cloud-setup)

1. Go to [Google Cloud Console](https://console.cloud.google.com/)
2. Create a new project or select an existing one
3. Enable the **Gmail API**:
    - Navigate to "APIs &amp; Services" &gt; "Library"
    - Search for "Gmail API" and enable it
4. Create OAuth2 credentials:
    - Go to "APIs &amp; Services" &gt; "Credentials"
    - Click "Create Credentials" &gt; "OAuth client ID"
    - Select "Desktop app" as the application type
    - Download the credentials JSON file
5. Save the credentials file:
    - Default location: `storage/app/gmail/credentials.json`
    - Or set a custom path via `GMAIL_CREDENTIALS_PATH`

Setup OAuth Token
-----------------

[](#setup-oauth-token)

Run the setup command to authenticate with your Google account:

```
php artisan os:gmail-mailer:setup
```

This will:

1. Display an authorization URL
2. Ask you to open the URL in your browser
3. Prompt you to enter the authorization code
4. Save the OAuth token for future use

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

[](#configuration)

### Environment Variables

[](#environment-variables)

Add to your `.env` file:

```
MAIL_MAILER=gmail-oauth2

# Optional: Custom paths for credentials and token
GMAIL_CREDENTIALS_PATH=/path/to/credentials.json
GMAIL_TOKEN_PATH=/path/to/token.json

# Optional: Application name shown in Google OAuth consent
GMAIL_APP_NAME="My Application"

# Optional: Default test recipient for the test command
GMAIL_TEST_RECIPIENT=test@example.com

# Optional: Logging
GMAIL_LOGGING_ENABLED=true
GMAIL_LOG_CHANNEL=stack
```

### Mail Configuration

[](#mail-configuration)

Add the Gmail mailer to your `config/mail.php`:

```
'mailers' => [
    // ... other mailers

    'gmail-oauth2' => [
        'transport' => 'gmail-oauth2',
    ],
],
```

Usage
-----

[](#usage)

### Send Email via Laravel Mail Facade

[](#send-email-via-laravel-mail-facade)

```
use Illuminate\Support\Facades\Mail;
use App\Mail\WelcomeEmail;

// Send using the default mailer (when MAIL_MAILER=gmail-oauth2)
Mail::to('user@example.com')->send(new WelcomeEmail());

// Or explicitly use the Gmail mailer
Mail::mailer('gmail-oauth2')
    ->to('user@example.com')
    ->send(new WelcomeEmail());
```

### Direct Service Usage

[](#direct-service-usage)

```
use Orangesoft\GmailMailer\Services\GmailService;

$gmail = app(GmailService::class);

$gmail->sendEmail(
    to: 'recipient@example.com',
    subject: 'Hello World',
    body: 'Welcome!This is a test email.',
    options: [
        'from' => 'sender@gmail.com',
        'fromName' => 'My App',
        'cc' => ['cc@example.com'],
        'bcc' => ['bcc@example.com'],
        'replyTo' => 'reply@example.com',
    ]
);
```

Commands
--------

[](#commands)

### Setup OAuth

[](#setup-oauth)

```
php artisan os:gmail-mailer:setup

# With custom paths
php artisan os:gmail-mailer:setup --credentials=/path/to/credentials.json --token=/path/to/token.json
```

### Test Email

[](#test-email)

```
# Send a test email
php artisan os:gmail-mailer:test user@example.com

# With custom subject
php artisan os:gmail-mailer:test user@example.com --subject="Custom Subject"

# Check token status only (no email sent)
php artisan os:gmail-mailer:test --check-only
```

Token Refresh
-------------

[](#token-refresh)

The package automatically refreshes expired OAuth tokens. If the refresh token becomes invalid, re-run:

```
php artisan os:gmail-mailer:setup
```

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

[](#troubleshooting)

### Token Expired Error

[](#token-expired-error)

If you see "Gmail OAuth token has expired and cannot be refreshed", run:

```
php artisan os:gmail-mailer:setup
```

### Credentials Not Found

[](#credentials-not-found)

Ensure your credentials file exists at the configured path:

```
ls -la storage/app/gmail/credentials.json
```

### Permission Denied

[](#permission-denied)

Check file permissions:

```
chmod 600 storage/app/gmail/token.json
chmod 600 storage/app/gmail/credentials.json
```

### Check Configuration

[](#check-configuration)

Verify your setup:

```
php artisan os:gmail-mailer:test --check-only
```

Security
--------

[](#security)

- OAuth tokens are stored with restricted permissions (0600)
- Credentials and tokens should be added to `.gitignore`
- Never commit credential or token files to version control

Add to your `.gitignore`:

```
storage/app/gmail/credentials.json
storage/app/gmail/token.json

```

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](LICENSE).

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance69

Regular maintenance activity

Popularity11

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity43

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

Every ~2 days

Total

4

Last Release

184d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1e21ffc9e4aa71c5644306993e6b13e6a2204caa59ac91e9e0e63574136d112e?d=identicon)[justinmoh](/maintainers/justinmoh)

---

Top Contributors

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

---

Tags

laravelmailmaileroauth2transportgmail

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/orange-soft-laravel-gmail-mailer/health.svg)

```
[![Health](https://phpackages.com/badges/orange-soft-laravel-gmail-mailer/health.svg)](https://phpackages.com/packages/orange-soft-laravel-gmail-mailer)
```

###  Alternatives

[propaganistas/laravel-disposable-email

Disposable email validator

6023.0M6](/packages/propaganistas-laravel-disposable-email)[illuminate/mail

The Illuminate Mail package.

5910.6M498](/packages/illuminate-mail)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[illuminate/notifications

The Illuminate Notifications package.

513.1M1.1k](/packages/illuminate-notifications)[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M194](/packages/laravel-ai)[moonshine/moonshine

Laravel administration panel

1.3k253.1k81](/packages/moonshine-moonshine)

PHPackages © 2026

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