PHPackages                             flyhjaelp/gmail2laravel - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. flyhjaelp/gmail2laravel

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

flyhjaelp/gmail2laravel
=======================

A Laravel package to help manage multiple Gmail Clients on the same platform.

v0.9.5(6y ago)41.2k1MITPHPPHP ^7.1CI failing

Since Jan 3Pushed 6y ago1 watchersCompare

[ Source](https://github.com/Flyhjaelp/gmail2laravel)[ Packagist](https://packagist.org/packages/flyhjaelp/gmail2laravel)[ Docs](https://github.com/flyhjaelp/gmail2laravel)[ RSS](/packages/flyhjaelp-gmail2laravel/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (3)Versions (6)Used By (0)

Google2Laravel
==============

[](#google2laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/a2bc204aca58a66da69c9950475f5057d56397d0b669bbeb4b55d9d910aa9fd0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f666c79686a61656c702f676d61696c326c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/flyhjaelp/gmail2laravel)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](license.md)[![Total Downloads](https://camo.githubusercontent.com/2839306c96baf163a6c799f04444a97cc83d70cfa825aae8fce0e5c450d4bccb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f666c79686a61656c702f676d61696c326c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/flyhjaelp/gmail2laravel)[![Build Status](https://camo.githubusercontent.com/a86b0f4afcab2c1288607e1c5e2fac9e7ddcf17123418ed85c821fe20747b915/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f666c79686a61656c702f676d61696c326c61726176656c2f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/flyhjaelp/gmail2laravel)

A Laravel package to help manage multiple Gmail Clients on the same platform.

This package is build on version 2.0 of the Official google/apiclient package.

**Table of Contents**

- [Installation](#installation)
- [Usage](#usage)
    - [Requirements](#requirements)
    - [Instantiating a Google Client Object with multiple Gmail clients](#instantiating-a-google-client-object-with-multiple-gmail-clients)
    - [Calling a method](#calling-a-method)
    - [The full list of methods](#the-full-list-of-methods)
- [Setup](#setup)
    - [Google Developer project](#google-developer-project)
    - [Service account client](#service-account-client)
    - [Roles and Permissions](#roles-and-permissions)
- [Quotas](#quotas)
- [Exceptions and errors](#exceptions-and-errors)
- [Changelog](#changelog)
- [Testing](#testing)
- [Contributing](#contributing)
- [Security](#security)
- [Credits](#credits)
- [License](#license)

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

[](#installation)

You can use Composer or simply Download the Release

```
$ composer require flyhjaelp/gmail2laravel
```

Usage
-----

[](#usage)

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

[](#requirements)

- [ PHP 7.1.3 or higher](http://www.php.net/)
- [ Google/apiclient ](https://github.com/googleapis/google-api-php-client)

Instantiating a Google Client Object with multiple Gmail clients
----------------------------------------------------------------

[](#instantiating-a-google-client-object-with-multiple-gmail-clients)

```
$credentialsPath = "path/to/credentials/file.json";

$googleClient    =  new gmail2laravel($credentials);

$gmailClient     =  $googleClient->getGmailClient('your.email@domain.com');
```

Calling a method
----------------

[](#calling-a-method)

```
// get an email
$emails = $gmailClient->user_messages->get('your.email@domain.com',$messageId);

// fetching all labels
$labels =  $gmailClient->user_labels->listUsersLabels('me');
```

List of methods
---------------

[](#list-of-methods)

```
$googleClient  =  new gmail2laravel($credentials);

$googleClient()->getGmailClient($email)

$googleClient()->deleteGmailClient($email)

$googleClient()->getEmailsFromAllClients($email)

$googleClient()->availableClients($email)

$googleClient()->enableBatch($email)

$googleClient()->disableBatch($email)
```

Additional list of methods
--------------------------

[](#additional-list-of-methods)

These methods are being imported from the main Google Gmail Api Package, and can be called as explained in the Gmail API documentation, where a broader description of the parameters required and the response is being provided. Link are provided bellow to each resource.

- [Users](https://developers.google.com/gmail/api/v1/reference/users)
- [Drafts](https://developers.google.com/gmail/api/v1/reference/users/drafts)
- [History](https://developers.google.com/gmail/api/v1/reference/users/history)
- [Labels](https://developers.google.com/gmail/api/v1/reference/users/labels)
- [Messages](https://developers.google.com/gmail/api/v1/reference/users/messages)
- [Messages attachments](https://developers.google.com/gmail/api/v1/reference/users/messages/attachments)
- [Settings ](https://developers.google.com/gmail/api/v1/reference/users/settings)
- [Threads ](https://developers.google.com/gmail/api/v1/reference/users/threads)

Setup
-----

[](#setup)

Google Developer project
------------------------

[](#google-developer-project)

The package makes usage of the Google API library. To gain access to the emails, a Google Cloud Project has to be created. A guide on how to do that can be found on the Google SDK platform [ Link ](https://developers.google.com/assistant/sdk/guides/library/python/embed/config-dev-project-and-account)

*Note*: the domain extension is important, as you will be able to access emails only from that domain. When creating a new Gmail Client instance, a check will be done automatically if the supplied user email address exists inside the g suite domain.

Service account client
----------------------

[](#service-account-client)

After creating a new project, add **Gmail API** from the API Library and enable it on the project. After that, you need to assign it a **Service account client**, which you can create from the Google Console meu.

[![alt text](storage/img/api.png)](storage/img/api.png)

***Note*** : the service is available only for G-Suite users.

[![alt text](storage/img/credentials.png)](storage/img/credentials.png) After you generate a Service user, assign it to the project and provide it the wanted access rights. Its important to add it to the project and not to the Gmail Api, so you have access to other apis included in the project.

Its best practices to separate APIs into separate projects if they are not related in usage.

Keep in mind that you can have multiple services that are assigned to different tasks. You are limited to 100 services per project. The project limit is connected to the quota usage of each project. The quota usage is explained here: [ Quotas ](#Quotas)

Roles and Permissions
---------------------

[](#roles-and-permissions)

To access Gmail Resources through a Service account client, you need to assign roles and permission to it. Depending to what the purpose of the project is, you need to add the required permissions. An example

Quotas
------

[](#quotas)

For every Developer Project that usage the Gmail API, there is a quota usage measured by the Google servers. A list of the quota price can be found [ here](https://developers.google.com/gmail/api/v1/reference/quota).

Keep in mind , each type of request is calculated a different amount of quota. This quotas are being added to the *quota units per day* (1.000.000 default)

and the ***quota\_units\_per\_user\_per\_second*** ( 250 default).

Exceptions and errors
---------------------

[](#exceptions-and-errors)

*Mention* : keep in mind that these exceptions are being thrown by the Google API endpoints, and not by this package. The google project is a very strict environment and rules which may not be imediately obvious may take place. The official documentation provides answer to some of the best practices on how to manage and access the respu

**Domain wide delegation (DWD)**

```
Google_Service_Exception: {
  "error": "unauthorized_client",
  "error_description": "Client is unauthorized to retrieve access tokens using this method."
}
```

This is a common error when running an API call with a service account but not properly completing the domain-wide delegation (DWD) or because the authorization in the admin console has not propagated yet.

This [article](https://developers.google.com/admin-sdk/directory/v1/guides/delegation) explains in details the process of DWD.

**Domain wide delegation (DWD)**

```
Google_Service_Exception: {
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "forbidden",
    "message": "Delegation denied for your.email@domain.com"
   }
  ],
  "code": 403,
  "message": "Delegation denied for your.email@domain.com"
 }
}
```

This error happens when the Gmail Client is setup for a specific email address and then the method call is being provided in the arguments with a different user id/email. You need to manage in the call which GmailClient to use and provide as the user id the value of 'me', and the code will take the associated email in return. Example.

```
//direct call with direct return from the google client
$googleClient->$gmailClient('dave@gmail.com')->users_labels->listUsersLabels('me');
```

**Message not found**

```
Google_Service_Exception: {
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "notFound",
    "message": "Not Found"
   }
  ],
  "code": 404,
  "message": "Not Found"
 }
}
```

The message you are trying to fetch is no longer available on the email address, due to maybe permanent deletion or wrong message id. Keep in mind that in some cases, the *message id* is the same as the *thread id*

**Quota limit reached**

```
Google_Service_Exception: {
 "error": "rate_limit_exceeded"
}
```

Exceeding a rate limit will cause an HTTP *403* or *HTTP 429 Too Many Requests* response and your app should respond by retrying with exponential backoff. [Link](https://developers.google.com/gmail/api/guides/performance) to best practices guides to avoid exceeding the limits and how much quota each type of request uses [link](https://developers.google.com/gmail/api/v1/reference/quota).

Changelog
---------

[](#changelog)

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

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [contributing.md](contributing.md) for details and a todo list.

Security
--------

[](#security)

If you discover any security related issues, please email [author email](dtr@flyhjaelp.dk) instead of using the issue tracker.

*Note*: Its your responsibility to ensure the storage of the service credentials key. Do not publish them on your repo, and the path to the key, should never be stored directly.

Credits
-------

[](#credits)

- [Dan Traian Roman](https://github.com/dantraian)
- [All Contributors](../../contributors%5D)

License
-------

[](#license)

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

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity49

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 ~103 days

Total

5

Last Release

2272d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3253dc15c8b1a29479386b44411ae50861b2188f76a7698ea04758e1d5e8db15?d=identicon)[flyhjaelp](/maintainers/flyhjaelp)

---

Top Contributors

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

---

Tags

laravelgmail2laravel

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/flyhjaelp-gmail2laravel/health.svg)

```
[![Health](https://phpackages.com/badges/flyhjaelp-gmail2laravel/health.svg)](https://phpackages.com/packages/flyhjaelp-gmail2laravel)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[interaction-design-foundation/laravel-geoip

Support for multiple Geographical Location services.

17221.0k3](/packages/interaction-design-foundation-laravel-geoip)[nedwors/navigator

A Laravel package to ease defining navigation menus

433.1k](/packages/nedwors-navigator)[xefi/faker-php-laravel

Faker php integration with laravel

1915.1k](/packages/xefi-faker-php-laravel)[dcblogdev/laravel-junie

Install pre-configured guides for Jetbrains Junie

392.5k](/packages/dcblogdev-laravel-junie)

PHPackages © 2026

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