PHPackages                             ddomanskyi/laravel-gmail - 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. [API Development](/categories/api)
4. /
5. ddomanskyi/laravel-gmail

ActiveLibrary[API Development](/categories/api)

ddomanskyi/laravel-gmail
========================

Gmail API package for Laravel from Dacastro4 (https://github.com/dacastro4/laravel-gmail/) with multiaccounts handling improvement

v3.2.6(6y ago)18MITPHPPHP ^7.2

Since Feb 2Pushed 6y agoCompare

[ Source](https://github.com/ddomanskyi/laravel-gmail)[ Packagist](https://packagist.org/packages/ddomanskyi/laravel-gmail)[ RSS](/packages/ddomanskyi-laravel-gmail/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (12)Versions (61)Used By (0)

Laravel Gmail
=============

[](#laravel-gmail)

Thanks to Dacastro4 () for this package and to Igor Hmelevskoy () for improving this package to be able to use multiple gmail accounts at same time.

How to use multiple accounts
============================

[](#how-to-use-multiple-accounts)

```
$mail = new Mail('filenamejson@gmail.com');
$mail->to( "test@gmail.com", "Test Name");
$mail->subject( "Test" );
$mail->message( "my test message" );
$mail->send();

```

Gmail
=====

[](#gmail)

Gmail API for Laravel 6

You need to create an application in the [Google Console](https://console.developers.google.com/apis/credentials?project=robotic-jet-193118&authuser=1). Guidance [here](https://developers.google.com/gmail/api/quickstart/php#step_1_turn_on_the_api_name).

if you need **Laravel 5** compatibility please use version `2.0.x`.

Requirements
============

[](#requirements)

- &gt;= PHP 7.0 &lt;= PHP 7.3
- Laravel 6

Installation
============

[](#installation)

Add ddomanskyi/laravel-gmail-multiaccounts to composer.json.

`"ddomanskyi/laravel-gmail-multiaccounts": "^3.0"`

Run composer update to pull down the latest version.

Or run

`composer require ddomanskyi/laravel-gmail-multiaccounts`

Now open up `config/app.php` and add the service provider to your providers array.

```
'providers' => [
    Ddomanskyi\LaravelGmail\LaravelGmailServiceProvider::class,
]
```

Now add the alias.

```
'aliases' => [
    'LaravelGmail' => Ddomanskyi\LaravelGmail\Facade\LaravelGmail::class,
]
```

For laravel &gt;=5.5 that's all. This package supports Laravel new [Package Discovery](https://laravel.com/docs/5.5/packages#package-discovery).

Migration from 2.0 to 3.0
=========================

[](#migration-from-20-to-30)

Requires Laravel 6 and you only have to change the dependency to `"laravel/laravel": "^6.0"`

Migration from 1.0 to 2.0
=========================

[](#migration-from-10-to-20)

The only changed made was the multi credentials feature.

- Change your composer.json from `"ddomanskyi/laravel-gmail-multiaccounts": "^1.0"` to `"ddomanskyi/laravel-gmail-multiaccounts": "^2.0"`

I had to change version because of a typo and that might break apps calling those attributes.

All variable with the word "threat" was change to "thread" (yeah, I know.. sorry) Ex:

Mail Class `$threatId` =&gt; `$threadId`

Replyable Class `$mail->setReplyThreat()` =&gt; `$mail->setReplyThread()`

and so on.

Migration from 0.6 to 1.0
=========================

[](#migration-from-06-to-10)

The only changed made was the multi credentials feature.

- Change your composer.json from `"ddomanskyi/laravel-gmail-multiaccounts": "^0.6"` to `"ddomanskyi/laravel-gmail-multiaccounts": "^1.0"`

If you don't want the multi user credentials, you don't have to do anything else, if you do, you're going to have to login again to create a new credentials file per user.

Configuration
=============

[](#configuration)

You only have to set the following variables on your `.env` file and you'll be on your way:

```
GOOGLE_PROJECT_ID=
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
GOOGLE_REDIRECT_URI=
GOOGLE_ALLOW_MULTIPLE_CREDENTIALS
GOOGLE_ALLOW_JSON_ENCRYPT
```

To modify the scopes and the credentials file name, just run:

Run `php artisan vendor:publish --provider="Ddomanskyi\LaravelGmail\LaravelGmailServiceProvider"` and modify the config file `config/gmail.php`.

### Allow multi user credentials

[](#allow-multi-user-credentials)

To allow multi user credentials change `allow_multiple_credentials` to `true` in your config file or set the .env variable `GOOGLE_ALLOW_MULTIPLE_CREDENTIALS` to true if you're not using the config file.

### Allow encryption for json files

[](#allow-encryption-for-json-files)

To allow encryption for json files change `allow_json_encrypt` to `true` in your config file or set the .env variable `GOOGLE_ALLOW_JSON_ENCRYPT` to true if you're not using the config file.

### Available Scopes

[](#available-scopes)

- all *(this one doesn't exists on Gmail Scopes, I added it.)*
- compose
- insert
- labels
- metadata
- modify
- readonly
- send
- settings\_basic
- settings\_sharing

[More about Gmail API scopes](https://developers.google.com/gmail/api/auth/scopes)

Note: To change the scopes, users have to logout and login again.

#### Additional Scopes

[](#additional-scopes)

If for some reason you need to add additional scopes.

Add additional scopes in URL Style in config/gmail.php

```
 'additional_scopes' => [
            'https://www.googleapis.com/auth/drive',
            'https://www.googleapis.com/auth/documents',
            'https://www.googleapis.com/auth/spreadsheets'
    ],

```

Example
=======

[](#example)

Welcome Blade:
--------------

[](#welcome-blade)

```

    {{ LaravelGmail::user() }}
    @if(LaravelGmail::check())
        logout
    @else
        login
    @endif

```

Routes:
-------

[](#routes)

```
Route::get('/oauth/gmail', function (){
    return LaravelGmail::redirect();
});

Route::get('/oauth/gmail/callback', function (){
    LaravelGmail::makeToken();
    return redirect()->to('/');
});

Route::get('/oauth/gmail/logout', function (){
    LaravelGmail::logout(); //It returns exception if fails
    return redirect()->to('/');
});
```

Then if in your controller or wherever you want to do your logic, you do something like:

```
$messages = LaravelGmail::message()->subject('test')->unread()->preload()->all();
foreach ( $messages as $message ) {
    $body = $message->getHtmlBody();
    $subject = $message->getSubject();
}
```

Note that if you don't preload the messages you have to do something like: ` $body = $message->load()->getSubject();`and after that you don't have to call it again.

Documentation
=============

[](#documentation)

Basic
-----

[](#basic)

`LaravelGmail::getAuthUrl` Gets the URL to auth the user.

`LaravelGmail::redirect` You can use this as a direct method `Login`

`LaravelGmail::makeToken()` Set and Save AccessToken in json file (useful in the callback)

`LaravelGmail::logout` Logs out the user

`LaravelGmail::check` Checks if the user is logged in

Sending
-------

[](#sending)

```
use Ddomanskyi\LaravelGmail\Services\Message\Mail;

...

$mail = new Mail;

```

For `to`, `from`, `cc` and `bcc`, you can set an array of emails and name or a string of email and name.

`$mail->using( $token )` If you don't want to use the token file, you can use this function that sets the token to use in the request. It doesn't refresh

`$mail->to( $to, $name = null )` sets the recipient email and name as optional

`$mail->from( $from, $name = null )` sets sender's email

`$mail->cc( $cc, $name = null )` sets carbon copy

`$mail->bcc( $bcc, $name = null )` sets a blind carbon copy

`$mail->subject( $subject )` sets the subject of the email

`$mail->message( $message )` sets the body of the email

`$mail->view( 'view.name', $dataArray )` sets the body from a blade file

`$mail->attach( ...$path )` add file attachments to the email

`$mail->priority( $priority )` sets the priority of the email from 1 to 5

`$mail->reply()` replies to an existent email

`$mail->send()` sends a new email

`$mail->setHeader( $header, $value )` sets header to the email

Mail
----

[](#mail)

`$mail->getId` returns the email's ID

`$mail->getInternalDate` returns date in UNIX format

`$mail->getDate` returns a Carbon date from the header of the email

`$mail->getLabels` returns an array of all the labels of the email

`$mail->getHeaders` returns a collection of the header. Each header is an array with two rows key and value

`$mail->getSubject` returns an string of the subject

`$mail->getFrom` Returns an array with name and email of sender

`$mail->getFromName` Returns string of name

`$mail->getFromEmail` Returns string of email

`$mail->getTo` Returns an array with name and email of all recipients

`$mail->getDeliveredTo` Returns the email of the receiver

`$mail->getPlainTextBody` Returns the plain text version of the email

`$mail->getRawPlainTextBody` Returns the raw version of the body base64 encrypted

`$mail->hasAttachments` Returns a boolean if the email has attachments

`$mail->load` Load all the information of the email (labels, body, headers). You call this function on a single email. To load from the beginning see [preload()](#preload)

`$mail->getHeader( $headerName, $regex = null )` Returns the header by name. Optionally, you can execute a regex on the value

Labels
======

[](#labels)

`$mail->markAsRead` Removes the 'UNREAD' label from the email.

`$mail->markAsUnread` Adds the 'UNREAD' label to the email.

`$mail->markAsImportant` Adds the 'IMPORTANT' label to the email.

`$mail->markAsNotImportant` Removes the 'IMPORTANT' label from the email.

`$mail->addStar` Adds the 'STARRED' label to the email.

`$mail->removeStar` Removes the 'STARRED' label from the email.

`$mail->sendToTrash` Adds the 'TRASH' label to the email.

`$mail->removeFromTrash` Removes the 'TRASH' label from the email.

`$mail->addLabel($string|$array)` Add multiple or single label to the email

`$mail->removeLabel($string|$array)` Removes multiple or single label from the email

`$mail->getAttachments()` Get a collection of all the attachments on the email

`$mail->getAttachmentsWithData()` Get a collection of all the attachments on the email including the data

Attachment
----------

[](#attachment)

```
use Ddomanskyi\LaravelGmail\Services\Message\Attachment
...

$attachment = new Attachment;

```

`$attachment->getId` Returns the ID of the attachment

`$attachment->getFileName` Returns the file name of the attachment

`$attachment->getMimeType` Returns the mime type Ex: application/pdf

`$attachment->getSize` Returns the size of the attachment in bytes

`$attachment->getData` Get the all the information from the attachment. If you call `getAttachmentsWithData` you won't need this method.

`$attachment->saveAttachmentTo($path = null, $filename = null, $disk = 'local')` Saves the attachment on the storage folder. You can pass the path, name and disk to use.

Messages
--------

[](#messages)

`LaravelGmail::message()->all( $pageToken = null )` Returns all the emails from the inbox

`LaravelGmail::message()->take(2)->all( $pageToken = null )` The `take` method limits the emails coming from the query by the number set

`LaravelGmail::message()->get( $id )` Returns a single email with all the information

### Modifiers

[](#modifiers)

You can modify your query with these methods. For example:

To get all unread emails: `LaravelGmail::message()->unread()->all()`

`message()->unread()`

`message()->from( $email )`

`message()->in( $box = 'inbox' )`

`message()->hasAttachment()`

`message()->subject($subject)`

`->after($date)` and `->before($date)`

`message()->raw($query)` for customized queries

All the possible filters are in the [Filterable Trait](https://github.com/ddomanskyi/laravel-gmail-multiaccounts/blob/master/src/Traits/Filterable.php)

Of course you can use as a fluent api.

```

    LaravelGmail::message()
                ->from('someone@gmail.com')
                ->unread()
                ->in('TRASH')
                ->hasAttachment()
                ->all()
```

### Preload

[](#preload)

You can preload the body, header and the rest of every single email just by calling this method.

`LaravelGmail::preload()`

Example:

```

    LaravelGmail::message()
                ->from('someone@gmail.com')
                ->unread()
                ->in('TRASH')
                ->hasAttachment()
                ->preload()
                ->all()
```

### Frequent Issues

[](#frequent-issues)

#### Login Required

[](#login-required)

If you're getting the `Login Required` error, try creating the `gmail-json.json` file under `/storage/app/gmail/tokens/`.

Support on Beerpay
------------------

[](#support-on-beerpay)

Hey dude! Help me out for a couple of 🍻!

[![Beerpay](https://camo.githubusercontent.com/4ece737766405468a0c93bf588071571d826b61d28ab860846a29f060a4a262c/68747470733a2f2f626565727061792e696f2f64646f6d616e736b79692f6c61726176656c2d676d61696c2d6d756c74696163636f756e74732f62616467652e7376673f7374796c653d626565722d737175617265)](https://beerpay.io/ddomanskyi/laravel-gmail-multiaccounts) [![Beerpay](https://camo.githubusercontent.com/10a8a6aee777a7e511ffcb0fd849c9967fc70d357af4e351e16c3c73778e6c30/68747470733a2f2f626565727061792e696f2f64646f6d616e736b79692f6c61726176656c2d676d61696c2d6d756c74696163636f756e74732f6d616b652d776973682e7376673f7374796c653d666c61742d737175617265)](https://beerpay.io/ddomanskyi/laravel-gmail-multiaccounts?focus=wish)

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 80.2% 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 ~14 days

Recently: every ~9 days

Total

54

Last Release

2251d ago

Major Versions

v0.6.2 → v1.0.02019-04-18

v1.2 → v2.0.x-dev2019-06-26

v2.0.4 → v3.0.02019-08-13

PHP version history (4 changes)v0.1-betaPHP &gt;=5.4.0

v0.1PHP &gt;=7.0

v0.2PHP &gt;=5.6

3.0.x-devPHP ^7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/50967647ce05f886dffdd5d60dca2e85dad1c9287fc912e02bc31f96aeefe474?d=identicon)[ddomanskyi](/maintainers/ddomanskyi)

---

Top Contributors

[![dacastro4](https://avatars.githubusercontent.com/u/7808930?v=4)](https://github.com/dacastro4 "dacastro4 (105 commits)")[![ddomanskyi](https://avatars.githubusercontent.com/u/16400865?v=4)](https://github.com/ddomanskyi "ddomanskyi (9 commits)")[![nasatome](https://avatars.githubusercontent.com/u/18271791?v=4)](https://github.com/nasatome "nasatome (3 commits)")[![jtwiest](https://avatars.githubusercontent.com/u/1511751?v=4)](https://github.com/jtwiest "jtwiest (3 commits)")[![mylesduncanking](https://avatars.githubusercontent.com/u/19204499?v=4)](https://github.com/mylesduncanking "mylesduncanking (2 commits)")[![JonahKlimack](https://avatars.githubusercontent.com/u/20914272?v=4)](https://github.com/JonahKlimack "JonahKlimack (2 commits)")[![martinschenk](https://avatars.githubusercontent.com/u/635827?v=4)](https://github.com/martinschenk "martinschenk (2 commits)")[![yoloSwagSEO](https://avatars.githubusercontent.com/u/25053451?v=4)](https://github.com/yoloSwagSEO "yoloSwagSEO (1 commits)")[![igormatkovic](https://avatars.githubusercontent.com/u/2323435?v=4)](https://github.com/igormatkovic "igormatkovic (1 commits)")[![jesephan](https://avatars.githubusercontent.com/u/6947802?v=4)](https://github.com/jesephan "jesephan (1 commits)")[![matthewhutchings](https://avatars.githubusercontent.com/u/10011888?v=4)](https://github.com/matthewhutchings "matthewhutchings (1 commits)")[![avinash403](https://avatars.githubusercontent.com/u/31030044?v=4)](https://github.com/avinash403 "avinash403 (1 commits)")

---

Tags

apilaravelgmail

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/ddomanskyi-laravel-gmail/health.svg)

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

###  Alternatives

[dacastro4/laravel-gmail

Gmail API package for Laravel

312382.9k1](/packages/dacastro4-laravel-gmail)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k12.1M99](/packages/laravel-pulse)[andreaselia/laravel-api-to-postman

Generate a Postman collection automatically from your Laravel API

1.0k586.2k3](/packages/andreaselia-laravel-api-to-postman)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[essa/api-tool-kit

set of tools to build an api with laravel

52680.5k](/packages/essa-api-tool-kit)[api-platform/laravel

API Platform support for Laravel

59126.4k5](/packages/api-platform-laravel)

PHPackages © 2026

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