> For the complete documentation index, see [llms.txt](https://docs.graphlit.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.graphlit.dev/api-guides/use-cases/feeds/messaging/feed-create-gmail.md).

# Create Gmail Feed

## User Intent

"How do I sync Gmail messages? Show me Gmail feed configuration."

## Operation

**SDK Method**: `createFeed()` with FeedTypes.Email\
**Auth**: Google OAuth tokens

***

## Code Example (TypeScript)

```typescript
import { Graphlit } from 'graphlit-client';
import { FeedTypes, FeedServiceTypes, EmailListingTypes } from 'graphlit-client/dist/generated/graphql-types';

const graphlit = new Graphlit();

const feed = await graphlit.createFeed({
  name: 'Gmail Inbox',
  type: FeedTypes.Email,
  email: {
    type: FeedServiceTypes.GoogleEmail,
    google: {
      type: EmailListingTypes.Past,
      clientId: process.env.GOOGLE_CLIENT_ID!,
      clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
      refreshToken: process.env.GOOGLE_REFRESH_TOKEN!,
      readLimit: 100,
      inboxOnly: true,
      excludeSentItems: true
    },
    includeAttachments: true,
  },
  // Optional: add workflow for content processing
  // workflow: { id: workflow.createWorkflow.id }
});

console.log(`Created Gmail feed: ${feed.createFeed.id}`);
```

***

## Configuration

**type**: `EmailListingTypes.Past` or `EmailListingTypes.New`\
**readLimit**: Number of emails to sync\
**inboxOnly**: Only sync inbox (excludes other labels)\
**excludeSentItems**: Exclude sent messages\
**includeSpam**: Include spam folder (default: false)\
**includeDeletedItems**: Include trash (default: false)\
**includeAttachments**: Download email attachments\
**filter**: Gmail search filter (e.g., `"from:user@example.com has:attachment"`)

***

## Gmail OAuth Setup

1. Create project in Google Cloud Console
2. Enable Gmail API
3. Create OAuth 2.0 credentials (Web application)
4. Add redirect URI
5. Get refresh token via OAuth flow

***

## What Gets Synced

* Email subject, body, and headers
* Sender and recipient information
* Timestamps and labels
* Attachments (if enabled)
* Thread relationships

***

## Filtering Examples

**By sender**:

```typescript
filter: "from:boss@company.com"
```

**By date range**:

```typescript
filter: "after:2024/01/01 before:2024/12/31"
```

**With attachments**:

```typescript
filter: "has:attachment"
```

**By label**:

```typescript
filter: "label:important"
```

***

## Related

* [Outlook Email Feed](/api-guides/use-cases/feeds/messaging/feed-create-outlook-email.md) - Microsoft email
* [Slack Feed](/api-guides/use-cases/feeds/messaging/feed-create-slack.md) - Team messaging
* [Feed Operations](/api-guides/use-cases/feeds/feed-query.md) - Query and manage feeds


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.graphlit.dev/api-guides/use-cases/feeds/messaging/feed-create-gmail.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
