# 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](https://docs.graphlit.dev/api-guides/use-cases/feeds/messaging/feed-create-outlook-email) - Microsoft email
* [Slack Feed](https://docs.graphlit.dev/api-guides/use-cases/feeds/messaging/feed-create-slack) - Team messaging
* [Feed Operations](https://docs.graphlit.dev/api-guides/use-cases/feeds/feed-query) - Query and manage feeds
