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.
This commit is contained in:
Alejandro González
2025-08-10 01:12:15 +02:00
committed by GitHub
parent 80eb297284
commit df1499047c
4 changed files with 26 additions and 13 deletions

View File

@@ -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:

View File

@@ -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

View File

@@ -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::<u16>().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(())
}

View File

@@ -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