Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(labrinth): environment variables for more customizable SMTP #2886

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
4 changes: 3 additions & 1 deletion apps/labrinth/.env → apps/labrinth/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ TURNSTILE_SECRET=none
SMTP_USERNAME=none
SMTP_PASSWORD=none
SMTP_HOST=none
SMTP_PORT=25
SMTP_TLS=true

SITE_VERIFY_EMAIL_PATH=none
SITE_RESET_PASSWORD_PATH=none
Expand All @@ -105,4 +107,4 @@ STRIPE_WEBHOOK_SECRET=none

ADITUDE_API_KEY=none

PYRO_API_KEY=none
PYRO_API_KEY=none
14 changes: 13 additions & 1 deletion apps/labrinth/src/auth/email/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use lettre::message::header::ContentType;
use lettre::message::Mailbox;
use lettre::transport::smtp::authentication::Credentials;
use lettre::transport::smtp::client::{Tls, TlsParameters};
use lettre::{Address, Message, SmtpTransport, Transport};
use thiserror::Error;

Expand Down Expand Up @@ -34,9 +35,20 @@ pub fn send_email_raw(
let username = dotenvy::var("SMTP_USERNAME")?;
let password = dotenvy::var("SMTP_PASSWORD")?;
let host = dotenvy::var("SMTP_HOST")?;
let port = dotenvy::var("SMTP_PORT")?.parse::<u16>().unwrap_or(25);
let creds = Credentials::new(username, password);
let tls_settings =
if dotenvy::var("SMTP_TLS")?.parse::<bool>().unwrap_or(true) {
Tls::Wrapper(TlsParameters::new(host.clone())?)
} else {
Tls::None
};

let mailer = SmtpTransport::relay(&host)?.credentials(creds).build();
let mailer = SmtpTransport::relay(&host)?
.port(port)
.tls(tls_settings)
.credentials(creds)
.build();

mailer.send(&email)?;

Expand Down
2 changes: 2 additions & 0 deletions apps/labrinth/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,8 @@ pub fn check_env_vars() -> bool {
failed |= check_var::<String>("SMTP_USERNAME");
failed |= check_var::<String>("SMTP_PASSWORD");
failed |= check_var::<String>("SMTP_HOST");
failed |= check_var::<u16>("SMTP_PORT");
failed |= check_var::<bool>("SMTP_TLS");

failed |= check_var::<String>("SITE_VERIFY_EMAIL_PATH");
failed |= check_var::<String>("SITE_RESET_PASSWORD_PATH");
Expand Down
Loading