• Stars
    star
    636
  • Rank 68,561 (Top 2 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created over 1 year ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Email test server for development, written in Rust

MailCrab logo

MailCrab

Email test server for development, written in Rust.

Inspired by MailHog and MailCatcher.

MailCrab was created as an exercise in Rust, trying out Axum and functional components with Yew, but most of all because it is really enjoyable to write Rust code.

TLDR

docker run --rm -p 1080:1080 -p 1025:1025 marlonb/mailcrab:latest

Features

  • Accept-all SMTP server
  • Web interface to view and inspect all incoming email
  • View formatted mail, download attachments, view headers or the complete raw mail contents
  • Runs on all amd64 and arm64 platforms using docker
  • Just a 7.77 MB docker image

MailCrab screenshot

Technical overview

Both the backend server and the frontend are written in Rust. The backend receives email over an unencrypted connection on a configurable port. All email is stored in memory while the application is running. An API exposes all received email:

  • /api/messages return all message metadata
  • /api/message/[id] returns a complete message, given its id
  • /api/version returns version information about the executable
  • /ws send email metadata to each connected client when a new email is received

The frontend initially performs a call to /api/messages to receive all existing email metadata and then subscribes for new messages using the websocket connection. When opening a message, the /api/message/[id] endpoint is used to retrieve the complete message body and raw email.

The backend also accepts a few commands over the websocket, to mark a message as opened, to delete a single message or delete all messages.

Installation and usage

To run MailCrab only docker is required. Start MailCrab using the following command:

docker run --rm -p 1080:1080 -p 1025:1025 marlonb/mailcrab:latest

Open a browser and navigate to http://localhost:1080 to view the web interface.

Ports

The default SMTP port is 1025, the default HTTP port is 1080. You can configure the SMTP and HTTP port using environment variables (SMTP_PORT and HTTP_PORT), or by exposing them on different ports using docker:

docker run --rm -p 3000:1080 -p 2525:1025 marlonb/mailcrab:latest

Host

You can specify the host address Mailcrab will listen on for HTTP request using the HTTP_HOST environment variable. In the docker image the default address is 0.0.0.0, when running Mailcrab directly using cargo or a binary, the default is 127.0.0.1.

TLS

You can enable TLS and authentication by setting the environment variable ENABLE_TLS_AUTH=true. MailCrab will generate a key-pair and print the self-signed certificate. Any username/password combination is accepted. For example:

docker run --rm --env ENABLE_TLS_AUTH=true -p 1080:1080 -p 1025:1025 marlonb/mailcrab:latest

It is also possible to provide your own certificate by mounting a key and a certificate to /app/key.pem and /app/cert.pem:

docker run --rm --env ENABLE_TLS_AUTH=true -v key.pem:/app/key.pem:ro -v cert.pem:/app/cert.pem:ro -p 1080:1080 -p 1025:1025 marlonb/mailcrab:latest

Path prefix

You can configure a prefix path for the web interface by setting and environment variable named MAILCRAB_PREFIX, for example:

docker run --rm --env MAILCRAB_PREFIX=emails -p 1080:1080 -p 1025:1025 marlonb/mailcrab:latest

The web interface will also be served at http://localhost:1080/emails/

Reverse proxy

See the reverse proxy guide.

Retention period

By default messages will be stored in memory until mailcrab is restarted. This might cause an OOM when Mailcrab lives long enough and receives enough messages.

By setting MAILCRAB_RETENTION_PERIOD to a number of seconds, messages older than the provided duration will be cleared.

docker compose

Usage in a docker-compose.yml file:

version: '3.8'
services:
  mailcrab:
    image: marlonb/mailcrab:latest
    #        environment:
    #            ENABLE_TLS_AUTH: true # optionally enable TLS for the SMTP server
    #            MAILCRAB_PREFIX: emails # optionally prefix the webinterface with a path
    #        volumes:
    #           key.pem:/app/key.pem:ro # optionally provide your own keypair for TLS, else a pair will be generated
    #           cert.pem:/app/cert.pem:ro
    ports:
      - '1080:1080'
      - '1025:1025'
    networks: [default]

Sample messages

The sample directory contains a couple of test messages. These can be sent using by running:

cd backend/
cargo test send_sample_messages -- --ignored

Development

Install Rust and Trunk

# Add wasm as target if it it not present after following the install instructions for Trunk
rustup target add wasm32-unknown-unknown

# clone the code
git clone [email protected]:tweedegolf/mailcrab.git

# start the backend
cd backend
cargo run

# serve the frontend (in a new terminal window)
cd ../frontend
trunk serve

# optionally send test messages in an interval
cd ../backend
cargo test

More Repositories

1

teach-rs

A modular, reusable university course for Rust
Rust
2,720
star
2

storage-abstraction

Provides an abstraction layer for interacting with a storage; the storage can be local or in the cloud.
TypeScript
96
star
3

stackdump

A set of rust crates for making stack dumps and getting stack traces out of them
Rust
69
star
4

sequential-storage

A crate for storing data in flash memory with minimal need for erasing pages
Rust
66
star
5

statime

Implementation of the Precision Time Protocol (PTP) in Rust
Rust
36
star
6

sx126x-rs

A driver for the SX126X Family of LoRa modems
Rust
23
star
7

prometheus-bundle

A Symfony bundle for the TweedeGolf Prometheus client
PHP
23
star
8

nea

Fast webserver with predictable memory usage
Rust
23
star
9

minecraft-character-configurator

Simple Minecraft character configurator using React, Three.js and react-three or react-three-renderer.
JavaScript
17
star
10

cargo-minify

A tool to remove unused code from a Rust project.
Rust
16
star
11

lzjd-rs

Rust implementation of the LZJD algorithm (https://github.com/EdwardRaff/jLZJD)
Rust
15
star
12

parsed-model

Utility code that makes it easier to create React components from imported 3D-models. To be used in applications using react-three or react-three-renderer and Three.js.
JavaScript
14
star
13

collada2json

Converts Collada models to Threejs' own JSON format
JavaScript
13
star
14

rp1

Easily generate a REST-like CRUD API using Rocket and Diesel
Rust
13
star
15

async-heapless

Rust
11
star
16

swiftmailer-logger-bundle

Log emails sent with Swift Mailer in your Symfony2 project
PHP
10
star
17

prometheus-client

A PHP Client for Prometheus
PHP
10
star
18

media-bundle

Media manager bundle for Symfony2 and tinyMCE
PHP
9
star
19

embedded-async-timer

Async timers for embedded devices in Rust
Rust
9
star
20

kubikey

Google kubernetes engine access using a yubikey
Rust
8
star
21

tguard

A web-based sending and decrypting service for IRMAseal-encrypted messages
Rust
8
star
22

web-ar

Creating augmented reality applications using solely web technologies and JSAruco or JSARToolkit
JavaScript
7
star
23

lorawan

Rust
7
star
24

memory-serve

Fast static file serving for axum web applications
Rust
7
star
25

async-rtos-showdown

Git repository of the code for the async vs rtos showdown blogpost
C
7
star
26

rust-training

Material for Tweede golf's Rust Training
Rust
7
star
27

trustzone-m-tools

Rust
6
star
28

ansible-vault-rs

Decrypt ansible vault 1.1 files in Rust
Rust
6
star
29

nrf9160-rust-starter

Run rust on the nrf9160, with the SPM already included
Rust
6
star
30

pinterest-slider

Slideshow of all images in a Pinterest board. After logging in, you can select a public board and the app displays all images in that board one after each other by using a short cross-fade between 2 consecutive images.
JavaScript
5
star
31

parsed_model_examples

Examples showing how you can create React components from existing 3D models. To be used in applications that use Three.js i.c.w. react-three or react-three-renderer.
JavaScript
5
star
32

irma-jitsi

Immutable authenticated identities for Jitsi using IRMA
Go
4
star
33

symfony-okoa

Okoa Symfony base project
PHP
4
star
34

tglora

Rust
4
star
35

dis-bootloader

A rust bootloader for our internal project using the nRF9160 chip.
Rust
4
star
36

ads129xx

Rust driver for the TI ads129 AFE for ECG applications
Rust
4
star
37

collada2json_headless

Headless version of the Collada to JSON converter
JavaScript
4
star
38

hashcode2019

HashCode submission 2019 - Photo Slideshows - Rust
Rust
3
star
39

tweetnacl-bindgen

Exercise using bindgen to create rust bindings for tweetnacl
C
3
star
40

rust-workshop-exercises

Rust
3
star
41

media-browser

Frond-end scripts for the tweedegolf media bundle
JavaScript
3
star
42

irmars

Rust library for interfacing with irma servers.
Rust
3
star
43

nrf-modem-nal

An embedded-nal implementation for the nrf9160 modem
Rust
3
star
44

wall_configurator

Add Colladas of windows and doors to a wall. The wall is a Threejs Geometry.
JavaScript
2
star
45

gulp-include-file

Include the contents of a file in javascript as a string.
JavaScript
2
star
46

autoerror

Rust
2
star
47

collada-surface

Tool to create mixes of 3D models. Using Collada's and Three.js
JavaScript
2
star
48

irma-chat

A chat application, with some substantiated guarantees of knowing who you are chatting with.
Rust
2
star
49

stm32wlxx-hal

Hardware Abstraction Library for the ST stm32wlxx family of MCUs in Rust
Rust
2
star
50

generatorbundle

Okoa Generator bundle
PHP
2
star
51

laszip-rs

Read/write laz data from/to file and memory
Rust
2
star
52

vr-test4

Testing WebVR API
JavaScript
1
star
53

docker-php-fpm

1
star
54

workshop-embedded-twoparter

Rust
1
star
55

storage-abstraction-example

Example application of the storage abstraction library
TypeScript
1
star
56

docker-dev

1
star
57

threejs-rotations

Show how to rotate the root scene to create an intuitive first person setting
JavaScript
1
star
58

hashcode2021

Rust
1
star
59

id-contact

Documentation repository for ID-Contact
1
star
60

async-spi

Rust
1
star
61

max2034x

No-std Rust driver for the max2034x family of bock-boost converters
Rust
1
star
62

wkhtmltox-deb9

Binaries of wkhtmltopdf and wkhtmltoimage for Debian 9.
1
star
63

veilig-bellen

Place authenticated calls with Amazon Connect and IRMA
Go
1
star
64

okoabundle

Okoa Bundle
PHP
1
star
65

henk

A ~100 line reverse proxy daemon with OpenSSH as client.
Go
1
star
66

rust-sync-async-test-cases

Code used to make https://tweedegolf.nl/blog/62/measuring-power-consumption-sync-vs-async
Rust
1
star
67

slidev-theme-tweedegolf

Tweede golf Slidev theme
CSS
1
star
68

custom_geo

Create and edit rectangular holes in a Threejs 3D object
TypeScript
1
star
69

pcf85063a

rust driver for the pcf85063a real-time clock
Rust
1
star
70

embedded-workshop

Embedded Rust Workshop
Rust
1
star
71

tof10120-rs

Driver crate for the TOF-10120 Time-of-flight sensor in Rust
Rust
1
star
72

mio-async-executor

An example async executor that uses mio to respond to OS events
Rust
1
star
73

nvm-log

Non-volatile memory log message storage
Rust
1
star
74

spaeter

TDOA location detection device
Rust
1
star
75

tdoa-solver

Takes in time difference of arrival data and calculates the source of the signal
Rust
1
star
76

parcel-plugin-precaching-sw

Parcel plugin that creates a precaching serviceworker that is configurable via package.json
JavaScript
1
star
77

file-bundle

File and image manager for Symfony 3 projects
JavaScript
1
star