Skip to main content

Email-to-EML Secure Archiver

Project description

Email-to-EML Secure Archiver (EESA)

A Python-based command-line utility to programmatically retrieve emails from Gmail and Microsoft 365 and save them as RFC822-compliant .eml files.

โœจ Features

  • ๐Ÿ” Secure OAuth2 Authentication - Browser-based authentication with 2FA support
  • ๐Ÿ“ง Multi-Provider Support - Gmail and Microsoft 365 (Outlook)
  • ๐Ÿ” Advanced Filtering - Date-based, incremental sync, custom queries
  • ๐Ÿช Webhook Integration - Automatically send downloaded emails to webhook endpoints
  • ๐Ÿ’พ Incremental Checkpointing - Resume interrupted downloads
  • ๐Ÿ“ฆ Modern Package Management - UV/UVX support for easy installation and execution

๐Ÿš€ Quick Start

Installation

Using uvx (recommended - no installation needed):

uvx email-archiver --help

Using pip:

pip install email-archiver
email-archiver --help

From source:

git clone https://github.com/therealtimex/email-archiver
cd email-archiver
uv sync
uv run email-archiver --help

Basic Usage

# Download emails from Gmail since a specific date
email-archiver --provider gmail --since 2024-12-01

# Incremental sync (resume from last checkpoint)
email-archiver --provider gmail --incremental

# With webhook integration
email-archiver --provider gmail --since 2024-12-23 \
  --webhook-url https://your-webhook.com/endpoint \
  --webhook-secret "Bearer your-token"

๐Ÿ“– Documentation

๐ŸŽฏ Common Use Cases

Daily Email Backup

email-archiver --provider gmail --incremental

Archive Specific Emails

# Emails with attachments
email-archiver --provider gmail --query "has:attachment" --since 2024-01-01

# From specific sender
email-archiver --provider gmail --query "from:important@example.com"

Webhook Integration

# Send emails to processing endpoint
email-archiver --provider gmail --incremental \
  --webhook-url https://api.example.com/emails \
  --webhook-secret "Bearer sk_live_abc123"

Custom Download Directory

# Save to specific folder
email-archiver --provider gmail --since 2024-12-01 \
  --download-dir /path/to/backup/emails

โš™๏ธ Configuration

Gmail Setup

  1. Create a project in Google Cloud Console
  2. Enable Gmail API
  3. Create OAuth 2.0 credentials (Desktop App)
  4. Save credentials as config/client_secret.json

Microsoft 365 Setup

  1. Register app in Azure Portal
  2. Add Mail.Read permission
  3. Update config/settings.yaml with your Client ID

See Quick Start Guide for detailed instructions.

๐Ÿช Webhook Integration

EESA can automatically POST downloaded .eml files to a webhook endpoint:

Via CLI:

email-archiver --provider gmail --since 2024-12-01 \
  --webhook-url https://webhook.site/your-id \
  --webhook-secret "Bearer token"

Via Configuration:

# config/settings.yaml
webhook:
  url: "https://your-webhook.com/endpoint"
  enabled: true
  headers:
    Authorization: "Bearer your-token"

๐Ÿ“‹ Command-Line Arguments

Argument Description
--provider {gmail,m365} Email provider (required)
--since YYYY-MM-DD Download emails since date
--incremental Resume from last checkpoint
--query STRING Custom search query
--webhook-url URL Webhook endpoint URL
--webhook-secret SECRET Authorization header for webhook
--download-dir PATH Custom download directory

See API Reference for complete documentation.

๐Ÿ”ง Requirements

  • Python 3.9+
  • Gmail API credentials (for Gmail)
  • Azure AD app registration (for M365)

๐Ÿ“ Project Structure

email-archiver/
โ”œโ”€โ”€ email_archiver/         # Main package
โ”‚   โ”œโ”€โ”€ main.py            # CLI entry point
โ”‚   โ””โ”€โ”€ core/              # Core modules
โ”‚       โ”œโ”€โ”€ gmail_handler.py
โ”‚       โ”œโ”€โ”€ graph_handler.py
โ”‚       โ””โ”€โ”€ utils.py
โ”œโ”€โ”€ config/
โ”‚   โ”œโ”€โ”€ settings.yaml      # Configuration file
โ”‚   โ”œโ”€โ”€ checkpoint.json    # Incremental sync state
โ”‚   โ””โ”€โ”€ client_secret.json # OAuth credentials (git-ignored)
โ”œโ”€โ”€ auth/                  # OAuth tokens (git-ignored)
โ”œโ”€โ”€ downloads/             # Downloaded .eml files
โ”œโ”€โ”€ docs/                  # Documentation
โ””โ”€โ”€ pyproject.toml         # Package configuration

๐Ÿ”’ Security

  • OAuth2 Only - No password storage
  • Read-Only Scopes - gmail.readonly and Mail.Read
  • Token Protection - Tokens stored with restricted permissions (chmod 600)
  • HTTPS Webhooks - Always use HTTPS for webhook endpoints

๐Ÿค Contributing

This project follows the specification in docs/SPECIFICATION.md.

๐Ÿ“„ License

See LICENSE file for details.

๐Ÿ†˜ Support

For issues or questions:

  1. Check the documentation
  2. Review examples
  3. Check logs in sync.log
  4. Open an issue on GitHub

๐ŸŽ“ Examples

Automation with Cron

# Daily backup at 2 AM
0 2 * * * email-archiver --provider gmail --incremental

Python Integration

import subprocess

subprocess.run([
    "email-archiver",
    "--provider", "gmail",
    "--since", "2024-12-01"
])

Using uvx (no installation)

# Run directly without installing
uvx email-archiver --provider gmail --since 2024-12-01

# Works from any directory
uvx email-archiver --help

See EXAMPLES.md for 21 more examples!


Built with โค๏ธ for secure email archiving

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

email_archiver-0.2.0.tar.gz (63.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

email_archiver-0.2.0-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file email_archiver-0.2.0.tar.gz.

File metadata

  • Download URL: email_archiver-0.2.0.tar.gz
  • Upload date:
  • Size: 63.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for email_archiver-0.2.0.tar.gz
Algorithm Hash digest
SHA256 3a236ef607d09f82660bc28c3350f4426176dcabe63bbf79c1a87c0315f202f3
MD5 54aabb433561935cc0c30b78a4bfe567
BLAKE2b-256 f033ac53815f842bb8ada556309865f8bc1b93d920484e160970593d31112957

See more details on using hashes here.

File details

Details for the file email_archiver-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: email_archiver-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for email_archiver-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 733a27a799727c80a5375e54ca72785f8ffbada7bc67a59839e60bf64ebc8c50
MD5 74cf4343c1c939d1c65741d1eff06742
BLAKE2b-256 c73fac2c3c23694cf843375140fc784f6daca10eb8e129a697745ad6033ff633

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page