Skip to content

When no mail providers are registered, fall back to no-op behavior #714

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

Closed
wants to merge 2 commits into from

Conversation

Tyrrrz
Copy link
Contributor

@Tyrrrz Tyrrrz commented Aug 30, 2024

#705 changed the behavior in regard to how the mail providers are configured:

  • Pre-PR, when the application configuration does not specify any mail provider, the emails are not sent.
  • Post-PR, when the application configuration does not specify any mail provider, the FileMailProvider is used.

The issue is that, in certain scenarios, the application may not be able to write data to the file system and thus may not use the FileMailProvider, making it a poor default choice. This happens, for example, when running in Docker, where the application is executed under an under-privileged user account for security reasons:

image

Additionally, there does not appear to be a way to set the NoopMailProvider through configuration as it's only defined in tests.

This PR reverts some of the user-facing behavior changes introduced in #705 and makes it so that no emails are sent when the configuration does not specify any mail provider.

Copy link

codecov bot commented Aug 30, 2024

Codecov Report

Attention: Patch coverage is 80.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 35.12%. Comparing base (5bcf203) to head (b106d59).
Report is 15 commits behind head on main.

Files with missing lines Patch % Lines
src/Common/Services/Mail/MailBootstrap.cs 33.33% 2 Missing ⚠️
src/Common/Services/Mail/AggregateMailProvider.cs 90.90% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #714      +/-   ##
==========================================
- Coverage   35.14%   35.12%   -0.03%     
==========================================
  Files         574      574              
  Lines       31176    31155      -21     
  Branches      930      929       -1     
==========================================
- Hits        10958    10942      -16     
+ Misses      20072    20067       -5     
  Partials      146      146              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@jrmccannon jrmccannon left a comment

Choose a reason for hiding this comment

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

I'd say this looks fine to me. Might be better if @jonashendrickx gave it a look as well.

}
}

_logger.LogCritical(FallBackFailedMessage);
Copy link
Contributor

Choose a reason for hiding this comment

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

If none of the registered e-mail providers can send, we need to know all of them fail. Because at that point the customers could be critically impacted being unable to log in.

return;
}
catch (Exception e)
{
_logger.LogError(e, "Failed to send message using provider '{Provider}'", providerConfiguration.Name);
Copy link
Contributor

Choose a reason for hiding this comment

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

This one was just to let us know when we fail to send using a specific provider, and log accordingly if it is not being logged by the provider itself specifically. It is to help us know when there is a specific issue with either a template or credentials of a specific provider.

{
o.Providers = new List<BaseMailProviderOptions>
{
new FileMailProviderOptions()
Copy link
Contributor

Choose a reason for hiding this comment

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

Removing it might not be a good idea, we could define a new mail provider to log to the console using a warning or info log level for testing. Or output to Memorycache or some other in-memory option.

For self-hosting keeping the file is better by default.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think all you need to do to fix the API testing image is the following:

#716

Copy link
Contributor

Choose a reason for hiding this comment

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

It is ready, the tests are passing

Copy link
Contributor

@jonashendrickx jonashendrickx left a comment

Choose a reason for hiding this comment

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

Would swallow error messages, if magic links fail we would want to know about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants