# Gmail Acessor 1 (`actual_zip/gmail-acessor-1`) Actor

- **URL**: https://apify.com/actual_zip/gmail-acessor-1.md
- **Developed by:** [Seema Gupta](https://apify.com/actual_zip) (community)
- **Categories:** Developer tools
- **Features:** Full permissions
- **Stats:** 19 total users, 0 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-usage

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## gmail-accessor

## 📧 Gmail Attachment Processor and Text Extractor

This Apify Actor connects to a user's Gmail account using the Google API, searches for emails based on a flexible query, and extracts text content from specific attachments (e.g., **PDFs**).

It is purpose-built for automation workflows, such as extracting structured data from documents like **Rate Confirmations**, **Invoices**, or **Purchase Orders** to feed into an LLM or another system.

***

### ✨ Key Features

- **Secure OAuth 2.0:** Uses a long-lived **Refresh Token** (`GMAIL_CREDENTIALS_JSON`) to access the Gmail API without storing passwords.
- **Flexible Filtering:** Leverages the full power of Gmail search operators (e.g., `subject:`, `from:`, `after:`) via the `gmailQuery` input.
- **Targeted Extraction:** Processes only attachments matching the specified `attachmentMimeTypes`.
- **PDF to Text Conversion:** Utilizes the `pdfminer.six` library to robustly convert PDF attachments into clean, searchable plain text.
- **LLM-Ready Output:** Stores the extracted text in a structured dataset, ready for AI and data analysis.

***

### ⚙️ Input Configuration

The Actor requires the following JSON input fields. Note the exact casing for the mandatory credential field.

| Field Name | Type | Required | Description | Default Value |
| :--- | :--- | :--- | :--- | :--- |
| **`GMAIL_CREDENTIALS_JSON`** | `String` | **Yes** | The full, unedited JSON string containing the Gmail OAuth 2.0 refresh token. **Critical for authentication.** | - |
| `gmailQuery` | `String` | No | A standard Gmail search query to filter messages. Example: `subject:"invoice" after:2024/01/01`. | `'subject:"Rate Confirmation for order #" has:attachment from:@scotlynn.com'` |
| `attachmentMimeTypes` | `Array<String>` | No | A list of MIME types for attachments to target. The Actor processes the **first matching attachment** found in an email. | `['application/pdf']` |

#### Example Input JSON

```json
{
  "GMAIL_CREDENTIALS_JSON": "YOUR_FULL_OAUTH_JSON_STRING_HERE",
  "gmailQuery": "subject:invoice after:2024/02/01 before:2024/03/01 has:attachment",
  "attachmentMimeTypes": ["application/pdf"]
}
```

***

### 🔒 Authentication Setup (How to get `GMAIL_CREDENTIALS_JSON`)

The `GMAIL_CREDENTIALS_JSON` is an OAuth 2.0 token object required for the Actor to access your Gmail. You must generate this object once outside of Apify.

#### 1. Google Cloud Console Setup

1. Navigate to the **Google Cloud Console** and create or select a project.
2. Enable the **Gmail API** service for your project.
3. Go to **APIs & Services > Credentials** and click **Create Credentials > OAuth client ID**.
4. Select **Application type: Desktop app** (this is the simplest type for generating the refresh token locally).
5. Save your generated **Client ID** and **Client Secret**.

#### 2. Token Generation Script

A local Python script must be run to generate the final token string. This process guides you through authorizing your application with Google and ensures a long-lived **refresh token** is issued.

The resulting script output is a single, complete JSON string containing the `client_id`, `client_secret`, and the required `refresh_token`.

**This entire output JSON string is the value you must provide for the `GMAIL_CREDENTIALS_JSON` input field.**

***

### 📊 Output Dataset Structure

The Actor pushes one record to the default dataset for every email attachment successfully processed and converted to text.

| Field Name | Type | Description |
| :--- | :--- | :--- |
| `messageId` | `String` | The unique ID of the Gmail message. |
| `subject` | `String` | The subject line of the email. |
| `date` | `String` | The date the email was received. |
| `attachmentName` | `String` | The file name of the extracted attachment. |
| `gmailQueryUsed` | `String` | The search query used for this run. |
| `targetMimes` | `Array<String>` | The MIME types the Actor was configured to search for. |
| **`attachmentContentText`** | **`String`** | **The full, extracted plain text content of the attachment (ready for downstream processing).** |

#### Example Dataset Item

```json
{
  "messageId": "19028a314b1f...",
  "subject": "Rate Confirmation for order #1296137",
  "date": "Fri, 5 Dec 2025 10:00:00 -0500",
  "attachmentName": "order_confirmation_1296137.pdf",
  "gmailQueryUsed": "subject:\"Rate Confirmation for order #\"...",
  "targetMimes": ["application/pdf"],
  "attachmentContentText": "Rate Confirmation\n\n1296137\n\nSCOTLYNN\n\nScotlynn USA Division V24.2\n 9597 Gulf Research Lane..."
}
```

## Actor input object example

```json
{}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {};

// Run the Actor and wait for it to finish
const run = await client.actor("actual_zip/gmail-acessor-1").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {}

# Run the Actor and wait for it to finish
run = client.actor("actual_zip/gmail-acessor-1").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{}' |
apify call actual_zip/gmail-acessor-1 --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,actual_zip/gmail-acessor-1"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/M7IxoPTUWyuLu9U0y/builds/weGDLug8xmWkYneqL/openapi.json
