Prompt Chain

Manage Gmail Communications with AI

GPT Action workflow connecting ChatGPT to Gmail API to read, send, list, and draft emails in authorized Google accounts with OAuth authentication.

Works with gmailgoogle

59
Spark score
out of 100
Updated 2 days ago
Version 1.0.0

Add to Favorites

Why it matters

Streamline your email management by leveraging AI to read, send, list, and draft emails within your authorized Gmail account. Automate responses and summarize conversations for enhanced productivity.

Outcomes

What it gets done

01

Summarize lengthy email threads and draft responses.

02

Draft and send emails based on AI analysis or previous communications.

03

List and manage incoming emails efficiently.

04

Integrate with other GPTs to send consolidated reports via email.

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/oai-gptactiongmail | bash

Steps

Steps in the chain

01
Set up a Google Cloud project

Before you get started, make sure you've a Google Cloud account and that the Gmail API is enabled. Set up a Google Cloud project as a prerequisite.

02
Enable Gmail API from Google API Library

Enable Gmail API from Google API Library in your Google Cloud project.

03
Add users to application if Testing

If application's 'Publishing Status' is 'Testing', ensure users are added to your application.

04
Go to Google Cloud Console

Go to the Google Cloud Console to begin authentication setup.

05
Navigate to API & Services > Credentials

Navigate to API & Services > Credentials in the Google Cloud Console.

06
Create new OAuth credentials

Create new OAuth credentials or use an existing one.

07
Locate and store OAuth credentials

Locate your OAuth Client ID & Client Secret and store both values securely.

08
Configure OAuth in ChatGPT

In ChatGPT, click on 'Authentication' and choose 'OAuth'. Enter Client ID, Client Secret, Authorization URL (https://accounts.google.com/o/oauth2/auth), Token URL (https://oauth2.googleapis.com/token), Scope (https://mail.google.com/), and Token (Default POST).

09
Copy callback URL from GPT Action

Copy the callback URL from the GPT Action.

10
Add callback URL to Authorized redirect URIs

In the 'Authorized redirect URIs' in Google Cloud Console, add your callback URL to finalize the Action.

Overview

GPT Action Library: Gmail

What it does

A GPT Action that connects ChatGPT to the Google Gmail API, enabling read, send, list, and draft operations on emails in authorized accounts through OAuth authentication.

How it connects

Use this when you need to connect ChatGPT to Gmail for programmatic email operations in authorized Google accounts.

Source README

GPT Action Library: Gmail

Introduction

This page provides an instruction & guide for developers building a GPT Action for a specific application. Before you proceed, make sure to first familiarize yourself with the following information:

This GPT Action provides an overview of how to connect to Google Gmail, Google’s Private & Secure Email for Personal or Business. This Action is connected to the Google Gmail APIs that can read, send, list, and draft emails in the authorized account.

Value + Example Business Use Cases

Value: The Gmail GPT will serve as a powerful tool to streamline communication processes, improve customer engagement, and optimize resource allocation.

Example Use Cases:

  • Manage internal communications by summarizing lengthy emails and drafting responses based on previous email threads.
  • Support agents can provide customers with instant responses adhering to a company’s communication guidelines, tone, and style.
  • Reference other GPTs , such as a data analsys GPT, and then ask for a draft/send of the consolidated analysis through email communication.

Application Information

Application Key Links

Check out these links from the application before you get started:

Application Prerequisites

Before you get started, make sure you’ve a Google Cloud account and that the Gmail API is enabled:

  • Set up a Google Cloud project
  • Enable Gmail API from Google API Library
  • If application’s “Publishing Status” is “Testing”, ensure users are added to your application

ChatGPT Steps

Custom GPT Instructions

Once you've created a Custom GPT, copy the text below in the Instructions panel. Have questions? Check out Getting Started Example to see how this step works in more detail.

**Context**
Act as an email assistant designed to enhance user interaction with emails in various ways. This GPT can assist with productivity by summarizing emails/threads, identifying next steps/follow-ups, drafting or sending pre-written responses, and programmatically interacting with third-party tools (e.g., Notion to-dos, Slack channel summaries, data extraction for responses). This GPT has full scope access to the GMAIL OAuth 2.0 API, capable of reading, composing, sending, and permanently deleting emails from Gmail.

**Instructions**
- Always conclude an email by signing off with logged in user's name, unless otherwise stated.
- Verify that the email data is correctly encoded in the required format (e.g., base64 for the message body).
- Email Encoding Process: 1\ Construct the email message in RFC 2822 format. 2\ Base64 encode the email message. 3\Send the encoded message using the API.
- If not specified, sign all emails with the user name.
- API Usage: After answering the user's question, do not call the Google API again until another question is asked.
- All emails created, draft or sent, should be in plain text.
- Ensure that the email format is clean and is formatted as if someone sent the email from their own inbox. Once a draft is created or email sent, display a message to the user confirming that the draft is ready or the email is sent.
- Check that the "to" email address is valid and in the correct format. It should be in the format "recipient@example.com". 
- Only provide summaries of existing emails; do not fabricate email content.
- Professionalism: Behave professionally, providing clear and concise responses.
- Clarification: Ask for clarification when needed to ensure accuracy and completeness in fulfilling user requests.
- Privacy and Security: Respect user privacy and handle all data securely.

OpenAPI Schema

Once you've created a Custom GPT, copy the text below in the Actions panel. Have questions? Check out Getting Started Example to see how this step works in more detail.

openapi: 3.1.0

info:
  title: Gmail Email API
  version: 1.0.0
  description: API to read, write, and send emails in a Gmail account.

servers:
  - url: https://gmail.googleapis.com

paths:
  /gmail/v1/users/{userId}/messages:
    get:
      summary: List All Emails
      description: Lists all the emails in the user's mailbox.
      operationId: listAllEmails
      parameters:
        - name: userId
          in: path
          required: true
          schema:
            type: string
          description: The user's email address. Use "me" to indicate the authenticated user.
        - name: q
          in: query
          schema:
            type: string
          description: Query string to filter messages (optional).
        - name: pageToken
          in: query
          schema:
            type: string
          description: Token to retrieve a specific page of results in the list.
        - name: maxResults
          in: query
          schema:
            type: integer
            format: int32
          description: Maximum number of messages to return.
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MessageList'
        '400':
          description: Bad Request
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
        '404':
          description: Not Found
        '500':
          description: Internal Server Error

  /gmail/v1/users/{userId}/messages/send:
    post:
      summary: Send Email
      description: Sends a new email.
      operationId: sendEmail
      parameters:
        - name: userId
          in: path
          required: true
          schema:
            type: string
          description: The user's email address. Use "me" to indicate the authenticated user.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Message'
      responses:
        '200':
          description: Email sent successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Message'
        '400':
          description: Bad Request
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
        '500':
          description: Internal Server Error

  /gmail/v1/users/{userId}/messages/{id}:
    get:
      summary: Read Email
      description: Gets the full email content including headers and body.
      operationId: readEmail
      parameters:
        - name: userId
          in: path
          required: true
          schema:
            type: string
          description: The user's email address. Use "me" to indicate the authenticated user.
        - name: id
          in: path
          required: true
          schema:
            type: string
          description: The ID of the email to retrieve.
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FullMessage'
        '400':
          description: Bad Request
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
        '404':
          description: Not Found
        '500':
          description: Internal Server Error

  /gmail/v1/users/{userId}/messages/{id}/modify:
    post:
      summary: Modify Label
      description: Modify labels of an email.
      operationId: modifyLabels
      parameters:
        - name: userId
          in: path
          required: true
          schema:
            type: string
          description: The user's email address. Use "me" to indicate the authenticated user.
        - name: id
          in: path
          required: true
          schema:
            type: string
          description: The ID of the email to change labels.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/LabelModification'
      responses:
        '200':
          description: Labels modified successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Message'
        '400':
          description: Bad Request
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
        '500':
          description: Internal Server Error

  /gmail/v1/users/{userId}/drafts:
    post:
      summary: Create Draft
      description: Creates a new email draft.
      operationId: createDraft
      parameters:
        - name: userId
          in: path
          required: true
          schema:
            type: string
          description: The user's email address. Use "me" to indicate the authenticated user.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Draft'
      responses:
        '200':
          description: Draft created successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Draft'
        '400':
          description: Bad Request
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
        '500':
          description: Internal Server Error

  /gmail/v1/users/{userId}/drafts/send:
    post:
      summary: Send Draft
      description: Sends an existing email draft.
      operationId: sendDraft
      parameters:
        - name: userId
          in: path
          required: true
          schema:
            type: string
          description: The user's email address. Use "me" to indicate the authenticated user.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SendDraftRequest'
      responses:
        '200':
          description: Draft sent successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Message'
        '400':
          description: Bad Request
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
        '500':
          description: Internal Server Error

components:
  schemas:
    MessageList:
      type: object
      properties:
        messages:
          type: array
          items:
            $ref: '#/components/schemas/Message'
        nextPageToken:
          type: string

    Message:
      type: object
      properties:
        id:
          type: string
        threadId:
          type: string
        labelIds:
          type: array
          items:
            type: string
        addLabelIds:
          type: array
          items:
            type: string
        removeLabelIds:
          type: array
          items:
            type: string
        snippet:
          type: string
        raw:
          type: string
          format: byte
          description: The entire email message in an RFC 2822 formatted and base64url encoded string.

    FullMessage:
      type: object
      properties:
        id:
          type: string
        threadId:
          type: string
        labelIds:
          type: array
          items:
            type: string
        snippet:
          type: string
        payload:
          type: object
          properties:
            headers:
              type: array
              items:
                type: object
                properties:
                  name:
                    type: string
                  value:
                    type: string
            parts:
              type: array
              items:
                type: object
                properties:
                  mimeType:
                    type: string
                  body:
                    type: object
                    properties:
                      data:
                        type: string

    LabelModification:
      type: object
      properties:
        addLabelIds:
          type: array
          items:
            type: string
        removeLabelIds:
          type: array
          items:
            type: string

    Label:
      type: object
      properties:
        addLabelIds:
          type: array
          items:
            type: string
        removeLabelIds:
          type: array
          items:
            type: string

    EmailDraft:
      type: object
      properties:
        to:
          type: array
          items:
            type: string
        cc:
          type: array
          items:
            type: string
        bcc:
          type: array
          items:
            type: string
        subject:
          type: string
        body:
          type: object
          properties:
            mimeType:
              type: string
              enum: [text/plain, text/html]
            content:
              type: string

    Draft:
      type: object
      properties:
        id:
          type: string
        message:
          $ref: '#/components/schemas/Message'

    SendDraftRequest:
      type: object
      properties:
        draftId:
          type: string
          description: The ID of the draft to send.
        userId:
          type: string
          description: The user's email address. Use "me" to indicate the authenticated user.

Authentication Instructions

Below are instructions on setting up authentication with this 3rd party application. Have questions? Check out Getting Started Example to see how this step works in more detail.

Pre-Action Steps

Before you set up authentication in ChatGPT, please take the following steps in the application.

  • Go to the Google Cloud Console

  • Navigate to API & Services > Credentials

  • Create new OAuth credentials (or use an existing one)

  • Locate your OAuth Client ID & Client Secret and store both values securely (see screenshot below)

In ChatGPT

In ChatGPT, click on "Authentication" and choose "OAuth". Enter in the information below.

Post-Action Steps

Once you've set up authentication in ChatGPT, follow the steps below in the application to finalize the Action.

  • Copy the callback URL from the GPT Action
  • In the “Authorized redirect URIs” (see screenshot above), add your callback URL

FAQ & Troubleshooting

  • Callback URL Error: If you get a callback URL error in ChatGPT, pay close attention to the screenshot above. You need to add the callback URL directly into GCP for the action to authenticate correctly
  • Schema calls the wrong project or dataset: If ChatGPT calls the wrong project or dataset, consider updating your instructions to make it more explicit either (a) which project / dataset should be called or (b) to require the user provide those exact details before it runs the query

Are there integrations that you’d like us to prioritize? Are there errors in our integrations? File a PR or issue in our github, and we’ll take a look.

Step 1: Set up a Google Cloud project

Before you get started, make sure you've a Google Cloud account and that the Gmail API is enabled. Set up a Google Cloud project as a prerequisite.

Step 2: Enable Gmail API from Google API Library

Enable Gmail API from Google API Library in your Google Cloud project.

Step 3: Add users to application if Testing

If application's 'Publishing Status' is 'Testing', ensure users are added to your application.

Step 4: Go to Google Cloud Console

Go to the Google Cloud Console to begin authentication setup.

Step 5: Navigate to API & Services > Credentials

Navigate to API & Services > Credentials in the Google Cloud Console.

Step 6: Create new OAuth credentials

Create new OAuth credentials or use an existing one.

Step 7: Locate and store OAuth credentials

Locate your OAuth Client ID & Client Secret and store both values securely.

Step 8: Configure OAuth in ChatGPT

In ChatGPT, click on 'Authentication' and choose 'OAuth'. Enter Client ID, Client Secret, Authorization URL (https://accounts.google.com/o/oauth2/auth), Token URL (https://oauth2.googleapis.com/token), Scope (https://mail.google.com/), and Token (Default POST).

Step 9: Copy callback URL from GPT Action

Copy the callback URL from the GPT Action.

Step 10: Add callback URL to Authorized redirect URIs

In the 'Authorized redirect URIs' in Google Cloud Console, add your callback URL to finalize the Action.

Discussion

Questions & comments · 0

Sign In Sign in to leave a comment.