feat: capture development email in MailHog via the Aspire sample (#73)#75
Merged
Conversation
Add a MailHog container to the AppHost (SMTP on 1025, web UI on 8025) and pre-configure the web app's EmailSender section to send through it. The settings come from configuration, not the database, so email keeps working after a database reset with no manual setup on the Email Settings page. MailHog accepts mail without authentication and does not advertise AUTH, and MailKit throws if AuthenticateAsync is called against such a server. Guard the call in SmtpEmailSender: only authenticate when the server advertises it and a username is configured. This also makes the foundation work with other no-auth relays. Closes #73
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #73.
What
1025, web UI on8025(open it from the Aspire dashboard to read captured mail). The web appWaitFors it.EmailSender__*config to send through MailHog. Because these come from configuration, not the database, email keeps working after a database reset with zero manual setup on the Email Settings page (the MailService uses theEmailSendersection as its bootstrap when no DB record exists).SmtpEmailSenderauth guard: MailHog accepts mail without authentication and doesn't advertiseAUTH, and MailKit throws ifAuthenticateAsyncis called against such a server. The sender now authenticates only when the server advertises it and a username is configured — so MailHog works, and so do other no-auth relays. Real servers that advertiseAUTHbehave exactly as before.Why config, not DB seeding
The issue asks that email survive a database reset without re-setup. Configuration is independent of the (persistent-volume) database, so a wipe/reset can't remove it and there's no re-seed-on-startup logic to maintain. The Email Settings page shows these as the "from configuration" baseline, and an admin can still save DB overrides on top.
Verification
dotnet build -c Release— 0 errors (AppHost compiles against Aspire 13.4.6;SmtpCapabilitiesguard compiles).dotnet test -c Release— 89/89.Note
MailHog SMTP/UI use fixed host ports
1025/8025for a stable local URL. If either conflicts on your machine, tell me and I'll switch to Aspire-assigned dynamic ports (wiring the SMTP endpoint intoEmailSender__Server/Portvia endpoint references).