/mail-archiver

Mail-Archiver is a web application for archiving, searching, and exporting emails from multiple accounts. Featuring folder sync, attachment support, mailbox migration and a dashboard.

Primary LanguageC#GNU General Public License v3.0GPL-3.0

πŸ“§ Mail-Archiver - Email Archiving System

A comprehensive solution for archiving, searching, and exporting emails

Docker .NET PostgreSQL Bootstrap GitHub Stars Buy Me a Coffee

✨ Key Features

πŸ“Œ General

  • Automated archiving of incoming and outgoing emails
  • Support for multiple accounts
  • Storage of email content and attachments
  • Scheduled synchronization at configurable intervals
  • Mobile and desktop optimized, multilingual responsive UI
  • Dark mode

πŸ” Advanced Search

  • Search across all archived emails
  • Filter by date range, sender, recipient, and more
  • Preview emails with attachment list

πŸ‘₯ Multi User

  • Create multiple user accounts
  • Assignment of different mail accounts to users

πŸ“Š Dashboard & Statistics

  • Account-specific statistics and overview
  • Storage usage monitoring
  • Top senders analysis

🧩 Supported Email Providers

  • IMAP: Traditional IMAP accounts with full synchronization capabilities
  • M365: Microsoft 365 mail accounts via Microsoft Graph API (setup guide)
  • IMPORT: Import-only accounts for migrating existing email archives without active synchronization

πŸ“€ Export Functions

  • Export entire mail accounts as mbox files or zipped EML archives
  • Export selected individual emails or email batches
  • Download attachments with original filenames preserved

πŸ“₯ Import Functions

  • MBox Import
  • EML Import (ZIP files with folder structure support)

πŸ” Restore Function

  • Restore a selection of emails or an entire mailbox to a destination mailbox

πŸ—‘οΈ Retention Policies

  • Configure automatic deletion of archived emails from the mailserver after a specified number of days
  • Set retention period per email account (e.g., delete emails after 30, 90, or 365 days)
  • Emails are only deleted from the server after they have been successfully archived
  • Helps manage storage space on the mailserver while maintaining a complete archive

🚨 Important note for retention policies

  • Requires IMAP Expunge support from the mail server to permanently delete emails
  • For Gmail accounts, Auto-Expunge must be disabled in Gmail settings under the "Forwarding and POP/IMAP" tab!

πŸ–ΌοΈ Screenshots

Dashboard

Mail-Archiver Dashboard

Archive

Mail-Archiver Archive

Email Details

Mail-Archiver Mail

πŸš€ Quick Start

Prerequisites

πŸ› οΈ Installation

  1. Install the prerequisites on your system

  2. Create a docker-compose.yml file

services:
  mailarchive-app:
    image: s1t5/mailarchiver:latest
    restart: always
    environment:
      # Database Connection
      - ConnectionStrings__DefaultConnection=Host=postgres;Database=MailArchiver;Username=mailuser;Password=masterkey;

      # Authentication Settings
      - Authentication__Enabled=true
      - Authentication__Username=admin
      - Authentication__Password=secure123!
      - Authentication__SessionTimeoutMinutes=60
      - Authentication__CookieName=MailArchiverAuth

      # MailSync Settings
      - MailSync__IntervalMinutes=15
      - MailSync__TimeoutMinutes=60
      - MailSync__ConnectionTimeoutSeconds=180
      - MailSync__CommandTimeoutSeconds=300
      - MailSync__AlwaysForceFullSync=false
      - MailSync__IgnoreSelfSignedCert=false

      # BatchRestore Settings
      - BatchRestore__AsyncThreshold=50
      - BatchRestore__MaxSyncEmails=150
      - BatchRestore__MaxAsyncEmails=50000
      - BatchRestore__SessionTimeoutMinutes=30
      - BatchRestore__DefaultBatchSize=50

      # BatchOperation Settings
      - BatchOperation__BatchSize=50
      - BatchOperation__PauseBetweenEmailsMs=50
      - BatchOperation__PauseBetweenBatchesMs=250

      # Selection Settings
      - Selection__MaxSelectableEmails=250

      # Npgsql Settings
      - Npgsql__CommandTimeout=900

      # Upload Settings for MBox files
      - Upload__MaxFileSizeGB=10
      - Upload__KeepAliveTimeoutHours=4
      - Upload__RequestHeadersTimeoutHours=2
    ports:
      - "5000:5000"
    networks:
      - postgres
    volumes:
      - ./data-protection-keys:/app/DataProtection-Keys
    depends_on:
      postgres:
        condition: service_healthy


  postgres:
    image: postgres:17-alpine
    restart: always
    environment:
      POSTGRES_DB: MailArchiver
      POSTGRES_USER: mailuser
      POSTGRES_PASSWORD: masterkey
    volumes:
      - ./postgres-data:/var/lib/postgresql/data
    networks:
      - postgres
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U mailuser -d MailArchiver"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 10s

networks:
  postgres:
  1. Edit the database configuration in the docker-compose.yml and set a secure password in the POSTGRES_PASSWORD variable and the ConnectionString.

  2. If you want to use authentication (which i'd strongly recommend) definie a Authentication__Username and Authentication__Password which is used for the admin user.

  3. Configure a reverse proxy of your choice with https and authentification to secure access to the application.

⚠️ Attention

The application itself does not provide encrypted access via https! It must be set up via a reverse proxy! Moreover the application is not build for public internet access!

  1. Initial start of the containers:
docker compose up -d
  1. Restart containers:
docker compose restart
  1. Access the application

  2. Login with your defined credentials and add your first email account:

  • Navigate to "Email Accounts" section
  • Click "New Account"
  • Enter your server details and credentials
  • Save and start archiving!
  • If you want, create other users and assign accounts.

πŸ” Security Note

  • Use strong passwords and change default credentials
  • Consider implementing HTTPS with a reverse proxy in production
  • Regular backups of the PostgreSQL database recommended

πŸ“ How To - Mailbox migration

It is also possible to migrate a mailbox to another target mailbox, for example when changing mail provider. The following steps are planned for this

  1. add the source account under the accounts
  2. synchronisation of the source account
  3. adding the target account
  4. synchronisation of the possibly still empty target account
  5. select β€˜Copy All Emails to Another Mailbox’ in the details under the accounts for the source account
  6. select the target account and the target folder in this account and start the migration. If there is a large amount of emails to be moved, this is carried out as a background task. The status and progress of this can be viewed in the Jobs tab.
  7. after the successful transfer, set the source account to β€˜Disabled’ under the accounts so that it is no longer archived in future.

πŸ“‹ Technical Details

Architecture

  • ASP.NET Core 8 MVC application
  • PostgreSQL database for email storage
  • MailKit library for IMAP communication
  • Background service for email synchronization
  • Bootstrap 5 and Chart.js for frontend

🀝 Contributing

Contributions welcome! Please open an Issue or Pull Request.

πŸ’– Support the Project

If you find this project useful and would like to support its continued development, you can buy me a coffee! Your support helps me dedicate more time and resources to improving the application and adding new features. While financial support is not required, it is greatly appreciated and helps ensure the project's ongoing maintenance and enhancement.

Buy Me a Coffee


πŸ“„ License: GNU GENERAL PUBLIC LICENSE Version 3 (see LICENSE file)