-
Notifications
You must be signed in to change notification settings - Fork 146
feat: add Hosting.MailPit docs for the pr under CommunityToolkit #2633
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
Open
prom3theu5
wants to merge
1
commit into
dotnet:main
Choose a base branch
from
prom3theu5:feature/mailpit
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+116
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,113 @@ | ||||||||||||
--- | ||||||||||||
title: .NET Aspire Community Toolkit MailPit integration | ||||||||||||
description: Learn how to use the .NET Aspire MailPit hosting integration to run the MailPit container. | ||||||||||||
ms.date: 02/17/2025 | ||||||||||||
--- | ||||||||||||
|
||||||||||||
# .NET Aspire Community Toolkit MailPit integration | ||||||||||||
|
||||||||||||
[!INCLUDE [includes-hosting](../includes/includes-hosting.md)] | ||||||||||||
|
||||||||||||
[!INCLUDE [banner](includes/banner.md)] | ||||||||||||
|
||||||||||||
In this article, you learn how to use the .NET Aspire MailPit hosting integration to run [MailPit](https://mailpit.axllent.org/) container. | ||||||||||||
|
||||||||||||
## Hosting integration | ||||||||||||
|
||||||||||||
To run the MailPit container, install the [📦 CommunityToolkit.Aspire.Hosting.MailPit](https://nuget.org/packages/CommunityToolkit.Aspire.Hosting.MailPit) NuGet package in the [app host](xref:dotnet/aspire/app-host) project. | ||||||||||||
|
||||||||||||
### [.NET CLI](#tab/dotnet-cli) | ||||||||||||
|
||||||||||||
```dotnetcli | ||||||||||||
dotnet add package CommunityToolkit.Aspire.Hosting.MailPit | ||||||||||||
``` | ||||||||||||
|
||||||||||||
### [PackageReference](#tab/package-reference) | ||||||||||||
|
||||||||||||
```xml | ||||||||||||
<PackageReference Include="CommunityToolkit.Aspire.Hosting.MailPit" | ||||||||||||
Version="*" /> | ||||||||||||
``` | ||||||||||||
|
||||||||||||
--- | ||||||||||||
|
||||||||||||
For more information, see [dotnet add package](/dotnet/core/tools/dotnet-add-package) or [Manage package dependencies in .NET applications](/dotnet/core/tools/dependencies). | ||||||||||||
|
||||||||||||
### Add MailPit resource | ||||||||||||
|
||||||||||||
In the app host project, register and consume the MailPit integration using the `AddMailPit` extension method to add the MailPit container to the application builder. | ||||||||||||
|
||||||||||||
```csharp | ||||||||||||
var builder = DistributedApplication.CreateBuilder(args); | ||||||||||||
|
||||||||||||
var mailpit = builder.AddMailPit("mailpit"); | ||||||||||||
|
||||||||||||
builder.AddProject<Projects.ExampleProject>() | ||||||||||||
.WithReference(mailpit); | ||||||||||||
|
||||||||||||
// After adding all resources, run the app... | ||||||||||||
``` | ||||||||||||
|
||||||||||||
When .NET Aspire adds a container image to the app host, as shown in the preceding example with the `docker.io/axllent/mailpit` image, it creates a new MailPit instance on your local machine. A reference to your MailPit resource (the `mailpit` variable) is added to the `ExampleProject`. | ||||||||||||
|
||||||||||||
For more information, see [Container resource lifecycle](../fundamentals/app-host-overview.md#container-resource-lifecycle). | ||||||||||||
|
||||||||||||
### Add MailPit resource with data volume | ||||||||||||
|
||||||||||||
To add a data volume to the MailPit resource, call the `Aspire.Hosting.MailPitBuilderExtensions.WithDataVolume` method on the MailPit resource: | ||||||||||||
|
||||||||||||
```csharp | ||||||||||||
var builder = DistributedApplication.CreateBuilder(args); | ||||||||||||
|
||||||||||||
var mailpit = builder.AddMailPit("mailpit") | ||||||||||||
.WithDataVolume("mailpit-data"); | ||||||||||||
|
||||||||||||
builder.AddProject<Projects.ExampleProject>() | ||||||||||||
.WithReference(mailpit); | ||||||||||||
|
||||||||||||
// After adding all resources, run the app... | ||||||||||||
``` | ||||||||||||
|
||||||||||||
The data volume is used to persist the MailPit data outside the lifecycle of its container. The data volume is mounted at the `/data` path in the MailPit container and when a `name` parameter isn't provided, the name is generated at random. For more information on data volumes and details on why they're preferred over [bind mounts](#add-mailpit-resource-with-data-bind-mount), see [Docker docs: Volumes](https://docs.docker.com/engine/storage/volumes). | ||||||||||||
|
||||||||||||
### Add MailPit resource with data bind mount | ||||||||||||
|
||||||||||||
To add a data bind mount to the MailPit resource, call the `Aspire.Hosting.MailPitBuilderExtensions.WithDataBindMount` method: | ||||||||||||
|
||||||||||||
```csharp | ||||||||||||
var builder = DistributedApplication.CreateBuilder(args); | ||||||||||||
|
||||||||||||
var mailpit = builder.AddMailPit("mailpit") | ||||||||||||
.WithDataBindMount( | ||||||||||||
source: @"C:\MailPit\Data"); | ||||||||||||
Comment on lines
+80
to
+82
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
|
||||||||||||
builder.AddProject<Projects.ExampleProject>() | ||||||||||||
.WithReference(mailpit); | ||||||||||||
|
||||||||||||
// After adding all resources, run the app... | ||||||||||||
``` | ||||||||||||
|
||||||||||||
[!INCLUDE [data-bind-mount-vs-volumes](../includes/data-bind-mount-vs-volumes.md)] | ||||||||||||
|
||||||||||||
Data bind mounts rely on the host machine's filesystem to persist the MailPit data across container restarts. The data bind mount is mounted at the `C:\MailPit\Data` on Windows (or `/MailPit/Data` on Unix) path on the host machine in the MailPit container. For more information on data bind mounts, see [Docker docs: Bind mounts](https://docs.docker.com/engine/storage/bind-mounts). | ||||||||||||
|
||||||||||||
## Client integration | ||||||||||||
|
||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
### Use a connection string | ||||||||||||
|
||||||||||||
MailPit automatically creates a `ConnectionStrings` configuration section which can be consumed by your client application. | ||||||||||||
|
||||||||||||
Then the connection string will be retrieved from the `ConnectionStrings` configuration section: | ||||||||||||
|
||||||||||||
```json | ||||||||||||
{ | ||||||||||||
"ConnectionStrings": { | ||||||||||||
"mailpit": "Endpoint=smtp://localhost:19530" | ||||||||||||
} | ||||||||||||
} | ||||||||||||
``` | ||||||||||||
|
||||||||||||
## See also | ||||||||||||
|
||||||||||||
- [MailPit](https://mailpit.axllent.org/) | ||||||||||||
- [.NET Aspire Community Toolkit GitHub repo](https://github.com/CommunityToolkit/Aspire) |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This article needs to be added to the TOC, under here: https://github.com/dotnet/docs-aspire/blob/main/docs/toc.yml#L289