Skip to content

Conversation

piprett
Copy link
Contributor

@piprett piprett commented Nov 3, 2024

This pull request adds two new environment variables, SMTP_PORT and SMTP_TLS. SMTP refers the protocol used to send emails.

SMTP_PORT configures which port to connect to on the SMTP server. It defaults to the standard and old default, 465.

SMTP_TLS is a boolean that defines if TLS security should be required to connect to the server. This defaults to the old value, true. Implementation wise I've copied the default values from the lettre crate we are using if the setting is enabled. This is how it behaved before, as we did not specify a TLS setting. If it is set to false it will instead use Tls::None.

This will help setting up labrinth for local development. You can use a mock SMTP server such as smtp4dev without setting up certificates and such.

This will help setting up labrinth for local development. You can now use a mock SMTP server such as smtp4dev. The TLS options will stay the same as before if set to `true`, and disabled when `false`.

Depends on modrinth#2883
@piprett piprett changed the title Smtp dev setup Add environment variables for SMTP development setup Nov 3, 2024
@piprett piprett changed the title Add environment variables for SMTP development setup feat(labrinth): environment variables for more customizable SMTP Nov 3, 2024
@piprett
Copy link
Contributor Author

piprett commented Nov 23, 2024

Prioritizing this over #2883, making that one a draft and removing dependency on it due to conflicts.

@AlexTMjugador AlexTMjugador added backend Relates to Modrinth Backend or API DevEx Improvements to developer experience labels Apr 21, 2025
@AlexTMjugador AlexTMjugador self-requested a review April 21, 2025 12:08
Copy link
Member

@AlexTMjugador AlexTMjugador left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR addresses a real issue and is looking great overall, thank you! I'd like to take stewardship of it and work toward getting it merged soon. @Erb3, could you please update the branch and take a look at the comments below?

piprett and others added 6 commits April 21, 2025 14:55
Co-authored-by: AlexTMjugador<me@alegon.dev>

Co-authored-by: Alejandro González <7822554+AlexTMjugador@users.noreply.github.com>
Signed-off-by: Erb3 <49862976+Erb3@users.noreply.github.com>
Signed-off-by: Erb3 <49862976+Erb3@users.noreply.github.com>
Replaced if/else with a switch statement. The new values for `SMPT_TLS` are `none`, `opportunistic_start_tls`, `requires_start_tls`, `tls`. When none of these values are supplied, it defaults to full TLS (`tls`), and throws a warning.

Resolves PR review
Signed-off-by: Erb3 <49862976+Erb3@users.noreply.github.com>
@piprett
Copy link
Contributor Author

piprett commented Apr 22, 2025

Good catches, I've updated the code. The default port is 465, and can be modified with SMTP_PORT. The SMTP_TLS now accepts the following values:

  • none
  • opportunistic_start_tls
  • requires_start_tls
  • tls

If none of these values are supplied to SMTP_TLS, it will default to TLS and throw a warning. I experimented with using an enum for the TLS setting, but in the end I used a simpler solution with a switch statement.

I have not tested the code with TLS as I don't have an email server. The none option has been tested with smtp4dev, and it works well with the following labrinth configuration:

SMTP_USERNAME=modrinth
SMTP_PASSWORD=frog
SMTP_HOST=localhost
SMTP_PORT=2525
SMTP_TLS=none

Thank you for your very friendly review!

@piprett piprett requested a review from AlexTMjugador April 22, 2025 08:38
Copy link
Member

@AlexTMjugador AlexTMjugador left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Splendid, thank you for your thoughtful PR and comments!

I've tested this on my end with Mailtrap’s STARTTLS-enabled SMTP development server, and everything worked great. It's also trivially clear that the direct TLS case has to function as expected, so we now have full coverage of all practical SMTP transport layer security protocols.

Would you be up for tweaking one last thing before merging?

Co-authored-by: Alejandro González <7822554+AlexTMjugador@users.noreply.github.com>
Signed-off-by: Erb3 <49862976+Erb3@users.noreply.github.com>
@piprett piprett requested a review from AlexTMjugador April 22, 2025 11:03
@AlexTMjugador AlexTMjugador enabled auto-merge April 22, 2025 11:11
@AlexTMjugador AlexTMjugador added this pull request to the merge queue Apr 22, 2025
Merged via the queue into modrinth:main with commit 6f902e2 Apr 22, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Relates to Modrinth Backend or API DevEx Improvements to developer experience

Development

Successfully merging this pull request may close these issues.

2 participants