Papercut.Service
August 23, 2026 ยท View on GitHub
Papercut.Service is a modern ASP.NET Core web application that serves as the backend service for Papercut SMTP. It provides SMTP email capture, a RESTful API for managing messages, and the embedded Angular web UI.
๐ฏ Purpose & Architecture
Papercut.Service is designed as a hybrid application that can operate in multiple modes:
- Standalone Service: Runs as a background Windows service for server deployments
- Web API Service: Always provides HTTP endpoints for message management
- SMTP Server: Captures SMTP messages sent to configurable ports
๐๏ธ Architecture & Code Organization
Papercut.Service follows Domain-Driven Design (DDD) principles with a clean, feature-based architecture organized into three main layers:
๐ DDD Layer Structure
src/Papercut.Service/
โโโ Application/ # Application Layer - Features & Use Cases
โ โโโ Messages/ # Message management feature
โ โ โโโ MessagesController.cs
โ โ โโโ MessagesHub.cs
โ โ โโโ NewMessageEventHandler.cs
โ โ โโโ MimePartFileStreamResult.cs
โ โ โโโ Models/ # Message-related DTOs and models
โ โโโ Health/ # Health check feature
โ โ โโโ HealthController.cs
โ โโโ SmtpServer/ # SMTP server configuration
โ โ โโโ Models/ # SMTP configuration models
โ โโโ WebUI/ # Web interface feature
โ โโโ StaticContentController.cs
โโโ Domain/ # Domain Layer - Business Logic & Entities
โ โโโ Notification/ # Domain events and notifications
โโโ Infrastructure/ # Infrastructure Layer - External Concerns
โโโ EmailAddresses/ # Email address utilities
โโโ Hosting/ # ASP.NET hosting configuration
โโโ IPComm/ # Inter-process communication
โโโ Logging/ # Logging infrastructure
โโโ Paths/ # File path management
โโโ Rules/ # Rule processing infrastructure
โโโ Servers/ # Server management
๐ฏ Layer Responsibilities
Application Layer
- Purpose: Orchestrates business operations and handles external requests
- Contents: Controllers, SignalR hubs, application services, DTOs
- Organization: Grouped by business feature (Messages, Health, SmtpServer, WebUI)
- Dependencies: Can depend on Domain and Infrastructure layers
Domain Layer
- Purpose: Contains core business logic, entities, and domain events
- Contents: Domain entities, value objects, domain services, events
- Organization: Grouped by domain concept (Notification, etc.)
- Dependencies: Should be independent (no dependencies on other layers)
Infrastructure Layer
- Purpose: Implements technical concerns and external system integrations
- Contents: Data access, external APIs, file systems, logging, hosting
- Organization: Grouped by technical capability (Logging, Hosting, etc.)
- Dependencies: Can depend on Domain layer for interfaces
๐ Feature-Based Organization Benefits
โ
High Cohesion - Related code stays together by business purpose
โ
Low Coupling - Clear boundaries between features and layers
โ
Team Ownership - Teams can own entire vertical slices
โ
Independent Evolution - Features can be modified without affecting others
โ
Easy Navigation - Intuitive file organization by business domain
โ
Testability - Clear boundaries make unit and integration testing focused
๐๏ธ Core Components
Backend Infrastructure
- ASP.NET Core 8.0 - Modern web application framework
- Autofac IoC Container - Dependency injection and modular architecture
- Serilog Logging - Structured logging with multiple sinks
- SmtpServer Library - SMTP protocol implementation
- MimeKit - Email message parsing and handling
Key Modules & Dependencies
- Papercut.Core - Core domain logic and infrastructure
- Papercut.Infrastructure.Smtp - SMTP server implementation
- Papercut.Infrastructure.IPComm - Inter-process communication
- Papercut.Message - Message repository and management
- Papercut.Rules - Message processing rules engine
- Papercut.Common - Shared utilities and extensions
Embedded Web UI
- Angular Web UI - Modern frontend embedded as static assets
๐ How to Run Papercut.Service
Option 1: Command Line Execution
Papercut.Service.exe
Option 2: Windows Service Installation
# Install and start as Windows service
Papercut.Service.exe install --sudo
Command Line Options
Get a full listing of available command line options:
Papercut.Service.exe help
โ๏ธ Configuration
Primary Configuration File
The service uses standard ASP.NET Core configuration files:
appsettings.json- Default configurationappsettings.Development.json- Development overridesappsettings.Production.json- Production overrides
Layered Settings Files
Beyond the ASP.NET Core configuration files, two user-facing files persist runtime changes:
-
Papercut.Service.Settings.json- User-editable settings that persist UI changes- Located in the same directory as
Papercut.Service.exe - Contains configuration with comments outlining options
- Changes made via the Papercut UI (e.g. SMTP IP/Port) are saved here automatically
- Note: rules are not stored here โ see
rules.jsonbelow
- Located in the same directory as
-
rules.json- Persisted rules- Located in the same directory as
Papercut.Service.exe - Rule changes made via the Papercut UI are synchronized to the service and saved here automatically
- Located in the same directory as
Configuration Priority: Papercut.Service.Settings.json > appsettings.{Environment}.json > appsettings.json
SMTP Server Configuration
{
"SmtpServer": {
"IP": "Any",
"Port": 25,
"MessagePath": "%BaseDirectory%\\Incoming",
"LoggingPath": "%DataDirectory%\\Logs;%BaseDirectory%\\Logs"
}
}
Automatic Synchronization
When running alongside the Papercut desktop client (Papercut.exe), configurations automatically synchronize:
- SMTP settings changes in the UI are reflected in the service
- Rule modifications are shared between client and service
- No manual configuration synchronization required
๐ API Endpoints
The service exposes a RESTful API for message management:
Message Operations
GET /api/messages- Retrieve paginated message listGET /api/messages/{id}- Get detailed message contentDELETE /api/messages- Delete all messagesGET /api/messages/{id}/raw- Download raw message fileGET /api/messages/{id}/sections/{index}- Download message attachments
Health Check
GET /health- Service health status
Features
- ETag Support - Efficient caching and conditional requests
- Pagination - Configurable page sizes for large message lists
- CORS Enabled - Cross-origin requests supported
- File Downloads - Raw message and attachment downloads
๐ Web UI Integration
The service includes an embedded Angular 17 web interface located in the Web/ directory:
- Modern Angular Architecture - Standalone components, signals, and latest features
- Material Design - Angular Material UI components
- Tailwind CSS - Utility-first styling framework
- Real-time Updates - Live message monitoring and management
- Responsive Design - Mobile-friendly interface
Note: The Web UI is embedded as static assets and served by the ASP.NET Core application. See Web/README.md for detailed frontend documentation.
Serve the Web UI Under a Path Prefix
When running behind a reverse proxy or Kubernetes ingress, the web UI (and API) can be served under a path prefix (e.g. http://host:8080/webmail/). Set HttpPathPrefix in appsettings.json or Papercut.Service.Settings.json:
{
"HttpPathPrefix": "/webmail"
}
Or via environment variable (useful for Docker):
docker run -d -p 8080:8080 -p 2525:2525 -e HttpPathPrefix=/webmail changemakerstudiosus/papercut-smtp:latest
The default (empty) serves the web UI at the root as before. Requests without the prefix continue to work, so proxies that strip the prefix are also supported โ but a prefix-stripping proxy must redirect the bare prefix (/webmail โ /webmail/) itself, since the app only sees / and cannot issue that redirect. Forwarding the full prefix (with HttpPathPrefix set) avoids this entirely.
๐ฆ Deployment Modes
1. Windows Service (Recommended for Production)
- Runs automatically on system startup
- Managed through Windows Service Control Manager
- Suitable for server environments
- Background operation without user interface
2. Console Application
- Interactive command-line execution
- Suitable for development and testing
- Real-time log output
- Manual startup and shutdown
3. Docker Container
DockerDefaultTargetOSconfigured for Linux- Containerized deployment option
- Scalable cloud deployments
๐ง Dependencies & Requirements
Runtime Requirements
- .NET 8.0 Runtime - Latest LTS version
- Windows Service support (for service installation mode)
External Libraries
- SmtpServer 10.0.1 - SMTP protocol handling
- MimeKit - Email message parsing
- Serilog - Structured logging framework
- Autofac - Dependency injection container
Optional Dependencies
- Node.js & npm - For building embedded Angular web UI
๐ Troubleshooting
Common Issues
- Port Conflicts: Ensure SMTP port (default 25) is available
- File Permissions: Service account needs write access to message directories
- Firewall: Configure Windows Firewall to allow SMTP traffic
Logging
Comprehensive logging is available through Serilog:
- Log files written to configured logging paths
- Structured JSON logging for analysis
- Multiple log levels (Information, Warning, Error, etc.)
๐ Related Documentation
Web/README.md- Angular frontend documentationWeb/TESTING.md- Web UI testing guidelines
License: Apache License, Version 2.0 Target Framework: .NET 8.0 Platform Support: Windows (primary), Linux (Docker)