| Crates.io | MailLaser |
| lib.rs | MailLaser |
| version | 1.0.0 |
| created_at | 2025-04-06 08:11:43.46644+00 |
| updated_at | 2025-04-06 08:11:43.46644+00 |
| description | An SMTP server that listens for incoming emails addressed to a specific recipient and forwards them as HTTP POST requests to a configured webhook. |
| homepage | |
| repository | https://github.com/Govcraft/mail-laser |
| max_upload_size | |
| id | 1622709 |
| size | 205,928 |
MailLaser is a lightweight, dedicated server application designed for one specific task: receiving emails sent to one or more designated email addresses and instantly forwarding the essential content (sender, recipient, subject, plain text body, and optionally the original HTML body) to a webhook URL you configure.
Think of it as a bridge: it converts incoming emails into structured HTTP POST requests (JSON format), making it easy to integrate email reception with modern web services, automation workflows, or custom applications without needing complex email handling libraries or a full mail server setup.
sender, recipient, subject, a plain text body (HTML is stripped), and optionally the original html_body if the email contained HTML. Attachments are ignored./health HTTP endpoint for monitoring service status.RUST_LOG environment variable.MAIL_LASER_TARGET_EMAILS.mailparse crate to parse the email structure (handling multipart messages), extracts the sender address, the specific recipient address, subject line, the plain text body (preferring text/plain part, otherwise generating from text/html via html2text), and the HTML body (if a text/html part exists).sender, recipient, subject, body (plain/generated text), html_body (optional raw HTML)) into a JSON object and sends it via an HTTPS POST request to the configured MAIL_LASER_WEBHOOK_URL./health endpoint that returns 200 OK if MailLaser is running.There are several ways to run MailLaser. Choose the one that best suits your needs.
This is the easiest way for automated deployments or if you already use Docker.
Pull the Image:
docker pull ghcr.io/govcraft/mail-laser:latest
# Or pull a specific version tag if needed
# docker pull ghcr.io/govcraft/mail-laser:vX.Y.Z
Run the Container: Provide environment variables and map ports.
docker run -d \
--name mail-laser \
-p 2525:2525 \
-p 8080:8080 \
-e MAIL_LASER_TARGET_EMAILS="target1@example.com,target2@example.com" \
-e MAIL_LASER_WEBHOOK_URL="https://your-webhook-url.com/path" \
-e MAIL_LASER_PORT="2525" \
-e MAIL_LASER_HEALTH_PORT="8080" \
-e RUST_LOG="info" \
--restart unless-stopped \
ghcr.io/govcraft/mail-laser:latest
(See Configuration section below for variable details)
This is a simple way to run MailLaser without needing Docker or the Rust toolchain.
Download: Go to the GitHub Releases page. Find the latest release and download the binary matching your operating system and architecture (e.g., mail_laser-linux-x86_64, mail_laser-macos-aarch64, mail_laser-windows-x86_64.exe).
(Linux/macOS Only) Make Executable: Open your terminal, navigate to the download location, and run:
chmod +x ./mail_laser-<your_platform_suffix>
Run: Open your terminal, navigate to the download location, set the required environment variables (see Configuration), and execute the binary:
MAIL_LASER_TARGET_EMAILS="target1@example.com,target2@example.com" \
MAIL_LASER_WEBHOOK_URL="https://your-webhook-url.com/path" \
./mail_laser-<your_platform_suffix>
set MAIL_LASER_TARGET_EMAILS=target1@example.com,target2@example.com
set MAIL_LASER_WEBHOOK_URL=https://your-webhook-url.com/path
.\mail_laser-windows-x86_64.exe
$env:MAIL_LASER_TARGET_EMAILS = "target1@example.com,target2@example.com"
$env:MAIL_LASER_WEBHOOK_URL = "https://your-webhook-url.com/path"
.\mail_laser-windows-x86_64.exe
(Alternatively, use a .env file as described in Configuration)
Use this method if you want to modify the code or prefer building it yourself.
git clone https://github.com/Govcraft/mail-laser.git
cd mail-laser
cargo build --release
The executable binary will be located at target/release/mail-laser (or mail-laser.exe on Windows).target/release directory:
MAIL_LASER_TARGET_EMAILS="target1@example.com,target2@example.com" \
MAIL_LASER_WEBHOOK_URL="https://your-webhook-url.com/path" \
./target/release/mail-laser
(Alternatively, use a .env file)MailLaser is configured entirely through environment variables, regardless of the running method. You can set these directly in your shell, pass them via Docker (-e or --env-file), or place them in a .env file in the same directory where you run the binary.
| Variable | Description | Required | Default |
|---|---|---|---|
MAIL_LASER_TARGET_EMAILS |
Comma-separated list of email addresses to accept. | Yes | - |
MAIL_LASER_WEBHOOK_URL |
The URL to forward the email payload to. | Yes | - |
MAIL_LASER_BIND_ADDRESS |
IP address for the server to listen on. | No | 0.0.0.0 |
MAIL_LASER_PORT |
Port for the SMTP server. | No | 2525 |
MAIL_LASER_HEALTH_BIND_ADDRESS |
IP address for the Health Check server. | No | 0.0.0.0 |
MAIL_LASER_HEALTH_PORT |
Port for the Health Check server. | No | 8080 |
RUST_LOG |
Controls logging level (see Logging section). | No | info |
Note on Docker: When running in Docker, MAIL_LASER_BIND_ADDRESS and MAIL_LASER_HEALTH_BIND_ADDRESS should generally be left as 0.0.0.0 to listen on all interfaces within the container. Port mapping (-p) handles exposing the service outside the container.
Example .env file:
MAIL_LASER_TARGET_EMAILS=alerts@mydomain.com,support@mydomain.com
MAIL_LASER_WEBHOOK_URL=https://hooks.example.com/services/T000/B001/XXX
# MAIL_LASER_PORT=2525 # Optional
# MAIL_LASER_HEALTH_PORT=8080 # Optional
RUST_LOG=debug # Optional, set desired log level
MailLaser uses the env_logger crate for logging. You can control the verbosity and scope of the logs using the RUST_LOG environment variable.
info (shows informational messages, warnings, and errors).RUST_LOG variable when running the binary or pass it via the -e flag in docker run.Common RUST_LOG values:
error: Show only critical errors.warn: Show errors and warnings.info: Show informational messages, warnings, and errors (Default).debug: Show detailed debugging information.trace: Show very verbose tracing information.Module-Specific Logging: You can also enable specific levels for MailLaser's internal modules (e.g., smtp, webhook):
RUST_LOG=mail_laser=debug: Show debug messages only from MailLaser code.RUST_LOG=info,mail_laser::smtp=debug: Show info level globally, but debug level for the SMTP module.Refer to the env_logger documentation for more advanced filtering options. Logs are written to standard output (stdout), which can be viewed using docker logs mail-laser when running in Docker, or directly in your terminal otherwise.
When MailLaser successfully receives and parses an email for one of the configured target addresses, it will send an HTTPS POST request to your MAIL_LASER_WEBHOOK_URL.
POSTapplication/jsonMailLaser/<version> (e.g., MailLaser/0.1.0){
"sender": "sender@example.com",
"recipient": "target1@example.com",
"subject": "Example Email Subject",
"body": "This is the plain text body content of the email.\\nLines are preserved, HTML tags are removed.",
"html_body": "<html><body><p>This is the <b>original</b> HTML content.</p></body></html>"
}
(Note: The html_body field will only be present if the incoming email contained HTML content.)
Note: MailLaser logs the status code of the webhook response (at info level or higher) but considers its job done once the request is sent. A failure response from your webhook (e.g., 4xx or 5xx) will be logged by MailLaser but will not cause the original email transaction to fail.
To receive emails from external sources (not just locally), you typically need to:
MX (Mail Exchanger) record for your domain (or subdomain) that points to the public IP address of the server where MailLaser is running.2525, or the port you mapped in Docker) is open for incoming TCP connections on your server's firewall and any network firewalls. You might need port forwarding if the server is behind NAT.Disclaimer: Properly configuring DNS and firewalls for public email reception can be complex and depends heavily on your hosting provider and network setup. Consult relevant documentation for your specific environment.
cargo buildcargo testThis project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
git checkout -b feature/your-feature).git commit -m 'Add some feature').git push origin feature/your-feature).