0

Is there any way to show e-mails from Gmail inbox in my SaaS website in PHP?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Mukesh
  • 23
  • 6
  • possible duplicate of [Reading messages using gmail api php](http://stackoverflow.com/questions/24503483/reading-messages-using-gmail-api-php) – trejder Nov 12 '14 at 07:24

1 Answers1

1

UPDATE: The OP edited the question asking for PHP client library.

The PHP Gmail Google Client Library is available but it is still in beta. The code snippets on how to use Google API are in their Github Repository but the Gmail API example is not available. This Gmail API definition file is a good place to get started.


You can use the Google Gmail API. It has client libraries in .NET, Java and Python. Cite from docs:

your app can use the API to add Gmail features like:

  • Read messages from Gmail
  • Send email messages
  • Modify the labels applied to messages and threads
  • Search for specific messages and threads

An example on how to use the API as per their quick start guide:

#!/usr/bin/python

import httplib2

from apiclient.discovery import build
from oauth2client.client import flow_from_clientsecrets
from oauth2client.file import Storage
from oauth2client.tools import run


# Path to the client_secret.json file downloaded from the Developer Console
CLIENT_SECRET_FILE = 'client_secret.json'

# Check https://developers.google.com/gmail/api/auth/scopes for all available scopes
OAUTH_SCOPE = 'https://www.googleapis.com/auth/gmail.readonly'

# Location of the credentials storage file
STORAGE = Storage('gmail.storage')

# Start the OAuth flow to retrieve credentials
flow = flow_from_clientsecrets(CLIENT_SECRET_FILE, scope=OAUTH_SCOPE)
http = httplib2.Http()

# Try to retrieve credentials from storage or run the flow to generate them
credentials = STORAGE.get()
if credentials is None or credentials.invalid:
  credentials = run(flow, STORAGE, http=http)

# Authorize the httplib2.Http object with our credentials
http = credentials.authorize(http)

# Build the Gmail service from discovery
gmail_service = build('gmail', 'v1', http=http)

# Retrieve a page of threads
threads = gmail_service.users().threads().list(userId='me').execute()

# Print ID for each thread
if threads['threads']:
  for thread in threads['threads']:
    print 'Thread ID: %s' % (thread['id'])

For more details, refer to the quick start guide: https://developers.google.com/gmail/api/quickstart/quickstart-python

There's a similar question on this matter.

trejder
  • 17,148
  • 27
  • 124
  • 216
Sandeep Raju Prabhakar
  • 18,652
  • 8
  • 35
  • 44