interface IMailer
Since 0.1.0

Email sender.

Examples

Example 1

const mailer = ctx.services.get<IMailer>(CAPABILITIES.MAIL);
await mailer.send({ to: user.email, subject: 'Welcome', text: 'Welcome!' });

Methods

send(message: MailMessage): Promise<void>

Sends an email.

sendTemplate(
template: string,
message: Omit<MailMessage, "html" | "text">,
data: Readonly<Record<string, unknown>>
): Promise<void>

Renders a named template and sends the result.

Since 0.6.0
optional
isHealthy(): Promise<boolean | undefined>

Reports whether the mail transport is REACHABLE right now, distinct from whether the mailer was constructed. Optional: a mailer whose transport exposes no side-effect-free probe omits it, and so does an implementation that does not answer the question at all.

A false means the transport was contacted and did not answer. An undefined means the question could not be asked โ€” never read it as healthy. This is the tri-state every reachability seam in the framework uses (IRedisClient.ping, StorageProvider.isHealthy, IMessageBroker.isHealthy), and it exists so a holder of an IMailer โ€” notification-plugin's email channel, an application's own health indicator โ€” can report the transport without importing mail-plugin, which AI_GUIDELINES ยง2.2 forbids.

Usage

import { type IMailer } from "mail-plugin/src/index.ts";