From df1499047ccc8f39d756d5beba60651237aca1c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Gonz=C3=A1lez?= <7822554+AlexTMjugador@users.noreply.github.com> Date: Sun, 10 Aug 2025 01:12:15 +0200 Subject: [PATCH] feat: set up Mailpit SMTP server as part of our Docker Compose file (#4151) * feat(labrinth): support STMP servers with no auth credentials * feat: set up Mailpit SMTP server as part of our Docker Compose services swarm * chore(docker-compose): fix healthcheck for mail service * feat(docker-compose): enable SpamAssassin integration through Postmark Unlike spinning up yet another container, this requires no configuration, and is good and simple enough for a funny little feature developers may occassionally use with non-confidential messages. --- .../docs/src/content/docs/contributing/labrinth.md | 2 +- apps/labrinth/.env.local | 10 +++++----- apps/labrinth/src/auth/email/mod.rs | 14 +++++++------- docker-compose.yml | 13 +++++++++++++ 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/apps/docs/src/content/docs/contributing/labrinth.md b/apps/docs/src/content/docs/contributing/labrinth.md index db80ae671..02c50b0f3 100644 --- a/apps/docs/src/content/docs/contributing/labrinth.md +++ b/apps/docs/src/content/docs/contributing/labrinth.md @@ -5,7 +5,7 @@ description: Guide for contributing to Modrinth's backend This project is part of our [monorepo](https://github.com/modrinth/code). You can find it in the `apps/labrinth` directory. The instructions below assume that you have switched your working directory to the `apps/labrinth` subdirectory. -[labrinth] is the Rust-based backend serving Modrinth's API with the help of the [Actix](https://actix.rs) framework. To get started with a labrinth instance, install docker, docker-compose (which comes with Docker), and [Rust]. The initial startup can be done simply with the command `docker-compose up`, or with `docker compose up` (Compose V2 and later). That will deploy a PostgreSQL database on port 5432 and a MeiliSearch instance on port 7700. To run the API itself, you'll need to use the `cargo run` command, this will deploy the API on port 8000. +[labrinth] is the Rust-based backend serving Modrinth's API with the help of the [Actix](https://actix.rs) framework. To get started with a labrinth instance, install docker, docker-compose (which comes with Docker), and [Rust]. The initial startup can be done simply with the command `docker-compose up`, or with `docker compose up` (Compose V2 and later). That will deploy a PostgreSQL database on port 5432, a MeiliSearch instance on port 7700, and a [Mailpit](https://mailpit.axllent.org/) SMTP server on port 1025, with a web UI to inspect sent emails on port 8025. To run the API itself, you'll need to use the `cargo run` command, this will deploy the API on port 8000. To get a basic configuration, copy the `.env.local` file to `.env`. Now, you'll have to install the sqlx CLI, which can be done with cargo: diff --git a/apps/labrinth/.env.local b/apps/labrinth/.env.local index 09b6e719d..aa07fa206 100644 --- a/apps/labrinth/.env.local +++ b/apps/labrinth/.env.local @@ -87,11 +87,11 @@ HCAPTCHA_SECRET=none SMTP_FROM_NAME=Modrinth SMTP_FROM_ADDRESS=no-reply@mail.modrinth.com -SMTP_USERNAME=none -SMTP_PASSWORD=none -SMTP_HOST=none -SMTP_PORT=465 -SMTP_TLS=tls +SMTP_USERNAME= +SMTP_PASSWORD= +SMTP_HOST=localhost +SMTP_PORT=1025 +SMTP_TLS=none SITE_VERIFY_EMAIL_PATH=auth/verify-email SITE_RESET_PASSWORD_PATH=auth/reset-password diff --git a/apps/labrinth/src/auth/email/mod.rs b/apps/labrinth/src/auth/email/mod.rs index 2220f389d..914a74271 100644 --- a/apps/labrinth/src/auth/email/mod.rs +++ b/apps/labrinth/src/auth/email/mod.rs @@ -39,7 +39,8 @@ pub fn send_email_raw( let password = dotenvy::var("SMTP_PASSWORD")?; let host = dotenvy::var("SMTP_HOST")?; let port = dotenvy::var("SMTP_PORT")?.parse::().unwrap_or(465); - let creds = Credentials::new(username, password); + let creds = + (!username.is_empty()).then(|| Credentials::new(username, password)); let tls_setting = match dotenvy::var("SMTP_TLS")?.as_str() { "none" => Tls::None, "opportunistic_start_tls" => { @@ -55,13 +56,12 @@ pub fn send_email_raw( } }; - let mailer = SmtpTransport::relay(&host)? - .port(port) - .tls(tls_setting) - .credentials(creds) - .build(); + let mut mailer = SmtpTransport::relay(&host)?.port(port).tls(tls_setting); + if let Some(creds) = creds { + mailer = mailer.credentials(creds); + } - mailer.send(&email)?; + mailer.build().send(&email)?; Ok(()) } diff --git a/docker-compose.yml b/docker-compose.yml index c14011154..955e6586f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -58,6 +58,19 @@ services: interval: 3s timeout: 5s retries: 3 + mail: + image: axllent/mailpit:v1.27 + container_name: labrinth-mail + ports: + - '1025:1025' + - '8025:8025' + environment: + MP_ENABLE_SPAMASSASSIN: postmark + healthcheck: + test: ['CMD', 'wget', '-q', '-O/dev/null', 'http://localhost:8025/api/v1/info'] + interval: 3s + timeout: 5s + retries: 3 labrinth: profiles: - with-labrinth