Gmail Integration

Connect your Gmail account to create email drafts directly from Archivus, powered by AI-generated content.


Overview

The Gmail integration allows you to create email drafts in your Gmail account from within Archivus. This is particularly useful for:

  • Sending AI-generated summaries via email
  • Sharing document analysis with colleagues
  • Creating professional emails from document content
  • Replying to email threads with document insights

Quick Start

  1. Connect Gmail - Go to Settings > Integrations and click Connect on Gmail
  2. Authorize - Sign in with your Google account and grant permissions
  3. Create Drafts - Use the “Send to Email” feature in document views or chat

Prerequisites

Before connecting Gmail:

  • Google Account - A personal or Google Workspace account
  • Gmail Access - Gmail must be enabled for your account
  • Archivus Account - Any paid plan

Connecting Gmail

Step 1: Navigate to Integrations

Go to Settings > Integrations in Archivus.

Step 2: Connect Gmail

  1. Find Gmail in the list of available integrations
  2. Click Connect
  3. You’ll be redirected to Google’s sign-in page

Step 3: Authorize Archivus

  1. Sign in with your Google account
  2. Review the permissions requested:
    • Create, read, update, and delete drafts - Required for draft creation
    • Send emails on your behalf - Only used when you explicitly send
  3. Click Allow to authorize

Step 4: Confirm Connection

After authorization:

  1. You’ll be redirected back to Archivus
  2. The Gmail integration will show as “Connected”
  3. Your Gmail email address will be displayed

Permissions Explained

Archivus requests minimal permissions:

Permission Purpose
Compose/Draft access Create drafts in your Gmail
Send emails Send drafts you approve

What Archivus CANNOT do:

  • Read your existing emails
  • Access your contacts
  • Modify your settings
  • Access other Google services

Creating Email Drafts

From Document Chat

  1. Chat with a document to generate insights
  2. Click Send to Email on any AI response
  3. A draft is created with the content
  4. Review and send from Gmail

From Document Summary

  1. Open a document’s summary view
  2. Click Share via Email
  3. Select content to include
  4. Draft is created in Gmail

From Compare Results

  1. Complete a document comparison
  2. Click Export to Email
  3. Comparison results become a draft

Draft Features

Markdown to HTML

Content is automatically converted:

  • Markdown headings → HTML headings
  • Bold/italic → Formatted text
  • Lists → Proper HTML lists
  • Links → Clickable hyperlinks
  • Code blocks → Formatted code

Pre-fill Options

When creating a draft, you can optionally specify:

Option Description
To Recipient email addresses
CC CC recipients
Subject Email subject line

Reply Support

Reply to existing email threads:

  1. Provide the Gmail thread ID
  2. Draft is created as a reply
  3. Maintains conversation context

API Reference

Get OAuth URL

Get the authorization URL to connect Gmail:

curl -X GET https://api.archivus.app/api/v1/gmail/auth-url \
  -H "Authorization: Bearer YOUR_API_KEY"

Response:

{
  "auth_url": "https://accounts.google.com/o/oauth2/v2/auth?...",
  "state": "random-state-token"
}

Get Connection Status

Check if Gmail is connected:

curl -X GET https://api.archivus.app/api/v1/gmail/connection \
  -H "Authorization: Bearer YOUR_API_KEY"

Response (Connected):

{
  "connected": true,
  "connection": {
    "id": "conn_abc123",
    "gmail_email": "user@gmail.com",
    "is_active": true,
    "connected_at": "2024-01-15T10:30:00Z",
    "last_used_at": "2024-01-20T14:22:00Z"
  }
}

Response (Not Connected):

{
  "connected": false
}

Create Draft

Create a draft in the user’s Gmail:

curl -X POST https://api.archivus.app/api/v1/gmail/draft \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "content": "# Summary\n\nThis is the document summary...",
    "to": ["recipient@example.com"],
    "cc": ["manager@example.com"],
    "subject": "Document Analysis Results"
  }'

Response:

{
  "draft_id": "r1234567890",
  "message_id": "1234567890abcdef",
  "gmail_url": "https://mail.google.com/mail/#drafts/1234567890abcdef",
  "message": "Draft created successfully"
}

Create Reply Draft

Create a draft that replies to an existing thread:

curl -X POST https://api.archivus.app/api/v1/gmail/draft \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "content": "Based on my analysis of the attached documents...",
    "reply_to_id": "thread_abc123def"
  }'

Disconnect Gmail

Remove the Gmail connection:

curl -X DELETE https://api.archivus.app/api/v1/gmail/connection \
  -H "Authorization: Bearer YOUR_API_KEY"

Response:

{
  "message": "Gmail disconnected successfully"
}

Use Cases

1. Share Document Summary

// After generating a document summary
const response = await fetch('/api/v1/gmail/draft', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${apiKey}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    content: documentSummary,
    to: ['team@company.com'],
    subject: `Summary: ${documentTitle}`
  })
});

const { gmail_url } = await response.json();
window.open(gmail_url, '_blank');

2. Send Analysis to Client

import requests

# Create draft with document analysis
result = requests.post(
    'https://api.archivus.app/api/v1/gmail/draft',
    headers={
        'Authorization': f'Bearer {api_key}',
        'Content-Type': 'application/json'
    },
    json={
        'content': f'''
# Document Analysis Report

## Key Findings
{key_findings}

## Recommendations
{recommendations}

---
*Generated by Archivus AI*
        ''',
        'to': [client_email],
        'subject': f'Analysis: {document_name}'
    }
)

print(f"Draft created: {result.json()['gmail_url']}")

3. Weekly Report Distribution

# Create weekly summary and draft email
summary = generate_weekly_summary()

draft = create_gmail_draft(
    content=summary,
    to=['leadership@company.com'],
    cc=['team@company.com'],
    subject=f'Weekly Document Report - Week {week_number}'
)

Security

Token Management

  • OAuth 2.0 - Industry-standard authorization flow
  • Encrypted storage - Tokens encrypted with AES-256-GCM
  • Auto-refresh - Tokens automatically refreshed before expiry
  • Secure revocation - Disconnect removes all stored tokens

Best Practices

  1. Review drafts - Always review before sending
  2. Limit recipients - Only share with intended recipients
  3. Check content - Verify AI-generated content is accurate
  4. Disconnect when done - Remove connection if no longer needed

Troubleshooting

“Gmail not connected”

Cause: No active Gmail connection for your account.

Solution:

  1. Go to Settings > Integrations
  2. Click Connect on Gmail
  3. Complete the authorization flow

“Gmail connection is inactive”

Cause: The connection token has expired or been revoked.

Solution:

  1. Go to Settings > Integrations
  2. Disconnect Gmail
  3. Reconnect and re-authorize

“Failed to create draft”

Cause: Various issues with draft creation.

Solutions:

  • Verify Gmail is connected
  • Check if the email addresses are valid
  • Ensure you have Gmail access (not blocked by workspace admin)
  • Try disconnecting and reconnecting

“OAuth state expired”

Cause: Authorization took longer than 5 minutes.

Solution:

  1. Start the connection process again
  2. Complete authorization within 5 minutes

“Content too large”

Cause: Draft content exceeds size limits.

Solution:

  • Split content into multiple drafts
  • Summarize content before sending
  • Remove unnecessary formatting

FAQ

Can I read my emails through Archivus?

No. Archivus only has permission to create drafts and send emails. It cannot read your existing emails.

Does Archivus send emails automatically?

No. Archivus only creates drafts. You must review and send emails manually from Gmail.

Can I connect multiple Gmail accounts?

Currently, one Gmail account per user. Contact support for multi-account needs.

What happens to drafts if I disconnect?

Drafts already created remain in your Gmail. Disconnecting only removes Archivus’s ability to create new drafts.

Is this available on mobile?

Yes. The Gmail integration works from any device where you access Archivus.


Endpoints Summary

Endpoint Method Description
/gmail/auth-url GET Get OAuth authorization URL
/gmail/callback GET OAuth callback (handled automatically)
/gmail/connection GET Get connection status
/gmail/connection DELETE Disconnect Gmail
/gmail/draft POST Create a draft

Next Steps


Questions? Contact support@archivusdms.com