Set up Posta with the Aspire integration

Цей контент ще не доступний вашою мовою.

⭐ Community Toolkit

Use the Posta hosting integration to run the email delivery platform with its required PostgreSQL and Redis resources. For a first walkthrough, see Get started with the Posta integration.

Aspire CLI — Додати пакет CommunityToolkit.Aspire.Hosting.Posta
aspire add communitytoolkit-posta

Aspire CLI інтерактивний; оберіть відповідний результат пошуку:

Aspire CLI — Приклад виводу
Select an integration to add:
> communitytoolkit-posta (CommunityToolkit.Aspire.Hosting.Posta)
> Other results listed as selectable options...

Posta requires a PostgreSQL database resource and a Redis resource. The integration configures references to both resources and waits for them during startup.

apphost.mts
import { createBuilder } from './.aspire/modules/aspire.mjs';
const builder = await createBuilder();
const postgres = await builder.addPostgres('postgres');
const database = await postgres.addDatabase('posta-db', 'posta');
const redis = await builder.addRedis('redis');
const posta = await builder.addPostaWithReferences('posta', database, redis);
await posta.withDataVolume();
const api = await builder.addProject('api', '../Api/Api.csproj');
await api.withReference(posta);
await builder.build().run();

The named volume mounts at /data and persists filesystem-backed attachments outside the container lifecycle. Use WithDataBindMount when you need to access those files from a host directory.

Use the PostaOptions callback for typed literal configuration such as URLs and feature flags. Pass secrets as Aspire parameters rather than embedding them in the AppHost source:

AppHost.cs
var encryptionKey = builder.AddParameter("posta-encryption-key", secret: true);
var smtpPassword = builder.AddParameter("posta-smtp-password", secret: true);
var posta = builder.AddPosta("posta", database, redis, options =>
{
options.Environment = "production";
options.WebUrl = "https://mail.example.com";
options.ApiUrl = "https://mail.example.com";
options.MetricsEnabled = true;
options.EncryptionKey = encryptionKey;
options.SystemSmtpHost = "smtp.example.com";
options.SystemSmtpPort = 587;
options.SystemSmtpPassword = smtpPassword;
options.SystemSmtpFrom = "notifications@example.com";
options.SystemSmtpEncryption = "starttls";
});

For production deployments, configure EncryptionKey and keep it stable across container restarts and upgrades. Posta uses this key to encrypt stored SMTP passwords.

Use the grouped parameter-based methods when values come from configuration or a publish-time parameter. The options accept Aspire parameter resources, including secret values:

AppHost.cs
var smtpHost = builder.AddParameterFromConfiguration("posta-smtp-host", "Posta:Smtp:Host");
var smtpPassword = builder.AddParameterFromConfiguration(
"posta-smtp-password",
"Posta:Smtp:Password",
secret: true);
var posta = builder.AddPosta("posta", database, redis)
.WithSystemSmtp(options =>
{
options.Host = smtpHost;
options.Port = builder.AddParameterFromConfiguration("posta-smtp-port", "Posta:Smtp:Port");
options.Password = smtpPassword;
});

The TypeScript AppHost export currently includes Posta creation, database and Redis references, and data mounts. The grouped configuration APIs shown above are exported for C# AppHosts.

Posta’s SMTP methods have different roles:

MethodPurposeEndpoint
WithSystemSmtpConfigures an external SMTP server for Posta’s own notifications.No listener is exposed.
WithInboundSmtpEnables receipt of email for domains managed by Posta.smtp, target port 2525 by default.
WithSmtpRelayEnables authenticated SMTP submission from applications.smtp-relay, target port 2526 by default.

Enable the SMTP relay when an application needs SMTP submission instead of the HTTP API:

AppHost.cs
var relayEnabled = builder.AddParameter("posta-relay-enabled", "true");
var posta = builder.AddPosta("posta", database, redis)
.WithSmtpRelay(options => options.Enabled = relayEnabled);

When enabling inbound STARTTLS, mount the certificate and key into the container and set their container paths in WithInboundSmtp. The SMTP endpoint’s host port is optional. If you configure a target port through an option, keep it aligned with the endpoint’s targetPort.

The hosting package includes these method groups:

MethodPurpose
AddPostaAdd Posta with PostgreSQL and Redis references, optional JWT secret, initial admin password and email, and an optional HTTP host port.
WithReferenceConfigure the Posta resource’s PostgreSQL or Redis connection.
WithDataVolume, WithDataBindMountPersist filesystem-backed attachments.
WithSystemSmtpConfigure the external SMTP server used for Posta notifications.
WithInboundSmtpConfigure Posta’s incoming SMTP endpoint.
WithSmtpRelayConfigure the authenticated SMTP relay endpoint.
WithS3BlobStorageConfigure S3-compatible attachment storage.
WithGoogleOAuthConfigure Google OAuth login.
WithEmailVerificationConfigure email verification.