mwagena/gmail-api-wrapper

Laravel 5 wrapper for Gmail API
516 6
Install
composer require mwagena/gmail-api-wrapper
License:MIT
Last Updated:May 16, 2017
Links: GitHub  ·  Packagist
Maintainer: niltonmelox

Gmail API wrapper for Laravel 5.x

Setup the api:

Step 1: Turn on the Gmail API

  • Use this wizard to create or select a project in the Google Developers Console and automatically turn on the API. ClickContinue, thenGo to credentials.
  • On theAdd credentialsto your project page, click theCancelbutton.
  • At the top of the page, select theOAuth consent screentab. Select anEmail address, enter aProduct nameif not already set, and click theSavebutton.
  • Select theCredentialstab, click theCreate credentialsbutton and selectOAuth client ID.
  • Select the application type webapp, enter the name of your choosings, fill out the redirect uri to your project and click theCreate button.
  • You will now receive a Client-ID and Client secret, copy and paste the settings somewere save since you will be needing these later.

Step 2: Sign in with the Client-ID and secret

Initiate the Gmail class

$gmail = new Gmail();
$gmail->getAuthUrl();

Use the returned code from the previous call to create a access + refresh token

$gmail->makeAccessToken($code);

Step 3: make use of it all

Initiate connection

$gmail = MartijnWagena\Gmail\Mail::create()
            ->setAccessToken($access_token, $refresh_token)
            ->setStartDate($date);

Check if token refresh needed

$gmail->isAccessTokenExpired();

Fetch all messages starting from the 'setStartDate', you only receive the ids of the messages

$gmail->fetch();

To fetch details of a message, use the code below

$gmail->getMessage($id, $threadId);

Send mails with the api

$gmail = MartijnWagena\Gmail\Send::create()->setAccessToken($access_token, $refresh_token);

$gmail->sendMail(
    [['email' => 'name@mail.com']],
    [['email' => 'name2@mail.com']],
    [['email' => 'name3@mail.com']],
    'your subject',
    'your message body',
    'inreplytomessageId',
    [] // array of attachments of type File
);

Step 5: If wanted, revoke access

$gmail = MartijnWagena\Gmail::create()->setAccessToken($access_token, $refresh_token);
$gmail->revokeAccess();

Related Packages

dacastro4/laravel-gmail

Gmail API package for Laravel

403,839 312
niltonmelox/gmail-api-easy

Laravel 5.* wrapper easy for the API Gmail

17 3
vlados/laravel-blade-crawler-detect

Boost Lighthouse and PageSpeed scores by hiding cookie banners, chat widgets and...

5,475 0
andhikamaheva/date

A date library to help you work with dates in different languages

13 1