elektromail
A minimal IMAP/SMTP mail server written in Rust, designed for development and testing purposes.
Features
- IMAP4rev2 server on port 1143 (default)
- SMTP server for receiving mail
- In-memory storage (no persistence)
- Zero configuration required
- RFC 9051 compliance test harness
Installation
Docker (Recommended)
Pull from GitLab Container Registry:
# Login to GitLab registry (if private)
# Pull latest image (multi-arch: amd64/arm64)
# Or pull a specific version
Run the container:
Cargo (crates.io)
Once published, add to your Cargo.toml:
[]
= "0.1"
Or install as a binary:
From Source
Quick Start
# Run the server
# Run with custom credentials
ELEKTROMAIL_USERS=demo:demo
# Run all tests
# Run RFC 9051 compliance tests only
Configuration
Environment variables:
ELEKTROMAIL_USERS- Comma-separateduser:passentries (optionaluser:email:passform supported)ELEKTROMAIL_AUTH_DISABLED- Set to1,true, oryesto disable authenticationSMTP_PORT- SMTP listen port (default2525)IMAP_PORT- IMAP listen port (default1143)BIND_ADDR- Bind address (default0.0.0.0)
Defaults:
- Credentials:
user/pass - Ports: SMTP
2525, IMAP1143
Docker
Build and run:
Tested and recommended stack:
- Rancher Desktop (Docker CLI / dockerd compatible)
Docker integration tests:
ELEKTROMAIL_DOCKER_TESTS=1
CI hint:
- Set
ELEKTROMAIL_DOCKER_HOST=dockerwhen using Docker-in-Docker.
GitLab CI setup guide: docs/gitlab-ci-setup.md
RFC 9051 Compliance Test Harness
This project includes a comprehensive test harness for validating IMAP server implementations against RFC 9051 (IMAP4rev2).
Test Coverage
210 tests covering all major IMAP commands:
| Section | Commands | Tests |
|---|---|---|
| 6.1 Any State | CAPABILITY, NOOP, LOGOUT | 19 |
| 6.2 Not Authenticated | LOGIN, STARTTLS, AUTHENTICATE | 22 |
| 6.3 Authenticated | SELECT, EXAMINE, CREATE, DELETE, RENAME, SUBSCRIBE, LIST, NAMESPACE, STATUS, APPEND, IDLE, ENABLE | 92 |
| 6.4 Selected | CLOSE, UNSELECT, EXPUNGE, SEARCH, FETCH, STORE, COPY, MOVE | 77 |
Testing Against Local Server
# Test the bundled elektromail server
Testing Against External IMAP Servers
The harness can validate any IMAP server:
# Test against an external server
RFC9051_TEST_HOST=imap.example.com \
RFC9051_TEST_PORT=993 \
RFC9051_TEST_USER=testuser \
RFC9051_TEST_PASS=testpass \
RFC9051_TEST_TLS=true \
Test Organization
Tests are organized by RFC section:
tests/rfc9051/
├── mod.rs # Configuration and test client
├── client.rs # IMAP test client with TLS support
├── response.rs # Response parser
├── assertions.rs # RFC-specific assertions
├── fixtures.rs # Test messages
└── section6_commands/
├── any_state/ # CAPABILITY, NOOP, LOGOUT
├── not_authenticated/ # LOGIN, STARTTLS, AUTHENTICATE
├── authenticated/ # SELECT, EXAMINE, CREATE, etc.
└── selected/ # FETCH, STORE, SEARCH, etc.
RFC Documentation
Local reference documentation is available in docs/rfc9051/:
- Section 1: Introduction
- Section 2: Protocol Overview
- Section 3: State Machine
- Section 4: Data Formats
- Section 5: Operational
- Section 6: Commands
- Section 7: Responses
IMAP Commands Reference
Any State
CAPABILITY- List server capabilitiesNOOP- No operation (keepalive)LOGOUT- End session
Not Authenticated
LOGIN user pass- Authenticate with credentialsSTARTTLS- Upgrade to TLSAUTHENTICATE mechanism- SASL authentication
Authenticated
SELECT mailbox- Open mailbox read-writeEXAMINE mailbox- Open mailbox read-onlyCREATE mailbox- Create new mailboxDELETE mailbox- Delete mailboxRENAME old new- Rename mailboxSUBSCRIBE mailbox- Subscribe to mailboxUNSUBSCRIBE mailbox- Unsubscribe from mailboxLIST ref pattern- List mailboxesNAMESPACE- Get namespace prefixesSTATUS mailbox (items)- Get mailbox statusAPPEND mailbox message- Add message to mailboxIDLE- Wait for updatesENABLE capability- Enable extension
Selected
CLOSE- Close mailbox, expunge deletedUNSELECT- Close mailbox, keep deletedEXPUNGE- Remove deleted messagesSEARCH criteria- Find messagesFETCH seq items- Retrieve message dataSTORE seq flags- Modify message flagsCOPY seq mailbox- Copy messagesMOVE seq mailbox- Move messages
Development
Running Specific Tests
# Run a specific command's tests
# Run with output
# Run single-threaded (useful for debugging)
Adding New Tests
- Create a new test file in the appropriate
section6_commands/subdirectory - Add the module to the parent
mod.rs - Use the
TestClientfromcrate::rfc9051 - Use assertions from
crate::rfc9051::assertions
Example:
use crate;
use crate*;
async
Credits
This project was inspired by GreenMail by Marcel May. GreenMail is an excellent Java-based email server for testing purposes. elektromail aims to provide a similar experience for developers who prefer a Rust-based solution.
License
This project is licensed under the European Union Public Licence v1.2 (EUPL-1.2) - see the LICENSE file for details.