GhaylStackDocumentationv1.0.2
العربيةWebsite
Shared services

Shared services

Email and action links

Configure SMTP or SendGrid, build safe messages and verify links in the correct frontend.

Use the shared mail contract

The Mailing building block exposes IMailService.SendAsync(MailRequest, CancellationToken). MailRequest carries recipients, subject, HTML body, a plain-text alternative, sender overrides, reply-to fields, CC/BCC, attachments and headers. Inject the service instead of constructing a provider client inside each feature.

MailOptions.UseSendGrid chooses the implementation. When false, the service uses SMTP through MailKit. When true, it uses a shared SendGrid client. The setting changes delivery; it does not change the message contract used by modules.

Configure the intended transport

Configuration key Purpose
MailOptions:From, DisplayName Default sender identity
MailOptions:Smtp:Host, Port SMTP endpoint
MailOptions:Smtp:UserName, Password SMTP authentication when required
MailOptions:Smtp:Security Connection-security mode
MailOptions:UseSendGrid Select SendGrid
MailOptions:SendGrid:ApiKey Provider credential

SMTP defaults to StartTls. A local mail catcher such as Mailpit can require None; implicit TLS on a provider's designated port uses SslOnConnect. Match the mode to the actual server. Do not disable transport security in production merely to make a connection error disappear.

Aspire exposes the development mail catcher and its endpoint. Use it to review generated messages without delivering test email to real recipients. Keep credentials in user secrets or the hosting secret mechanism.

Build HTML and text together

The HTML body is sent as text/html. Bare user-supplied text is therefore not automatically safe markup, and a URL written as text is not guaranteed to become a clickable link.

HtmlEmail provides Encode, Shell, LinkAction and Notice. LinkAction encodes its text and URL inputs and renders an anchor. Shell accepts trusted inner markup, so encode every interpolated user value before placing it there. Supply MailRequest.TextBody as a readable fallback for clients that do not render HTML.

For example, when adapting a feature to send an action link, build the HTML with HtmlEmail.LinkAction and provide the same destination in the plain-text body. The destination must come from the approved frontend-origin resolver, not arbitrary HTML supplied by a caller.

Send users to the correct application

Password-reset and confirmation links depend on FrontendOptions. DefaultOrigin is the fallback frontend address; AllowedOrigins defines the frontend origins the resolver accepts. The production API requires a valid absolute HTTP or HTTPS default origin.

When Admin and Dashboard have separate addresses, list the relevant origins. Otherwise a request can successfully send a message whose button opens the wrong application. CORS and frontend-link selection are different configurations; setting one does not complete the other.

Verify the complete message

Trigger a development password-reset or confirmation flow, open the captured message, check sender, subject, Arabic text, HTML and plain text, then follow its link. Verify the intended app, route and token handling. Do not copy live tokens into issue reports or screenshots.

For delivery failures inspect the selected provider, host, security mode and authentication. For a delivered but unusable link inspect frontend origins and the route that consumes the token. For background email inspect the email queue and the job execution path.

Implementation references

View MarkdownBack to top

Search documentation

Use ↑ ↓ to move, Enter to open and Esc to close.