@mxraven/mail - v0.6.0
    Preparing search index...

    Class Message

    A mutable, chainable builder for an email message.

    Chained methods return the receiver, so a message is normally composed in a single expression. A Message is not safe for concurrent use. It can be sent repeatedly; each send serializes the current state.

    const message = new Message()
    .from("Acme <noreply@acme.example>")
    .to("customer@example.com")
    .subject("Your receipt")
    .text("Thanks for your order.")
    .html("<p>Thanks for your order.</p>");
    Index
    • Appends an attachment.

      The data is retained by reference until the message is built. Callers must not mutate it in the meantime.

      Parameters

      Returns this

    • Appends a file attachment with an application/octet-stream content type.

      Parameters

      • filename: string
      • data: Uint8Array

      Returns this

    • Appends an inline attachment referenced by contentId, for example from cid: HTML.

      Parameters

      • filename: string
      • contentId: string
      • data: Uint8Array

      Returns this

    • Adds envelope recipients without a visible Bcc header.

      Parameters

      • addresses: string | readonly string[]

      Returns this

    • Adds envelope and Cc header recipients.

      Parameters

      • addresses: string | readonly string[]

      Returns this

    • Sets the Date header. When unset, the time of sending is used.

      Parameters

      • date: Date

      Returns this

    • Sets the envelope sender and the From header.

      Parameters

      • address: string

      Returns this

    • Appends a custom header.

      Parameters

      • name: string
      • value: string

      Returns this

    • Sets the HTML body.

      When both a text and an HTML body are set, the message is sent as multipart/alternative.

      Parameters

      • body: string

      Returns this

    • Sets the In-Reply-To header for threading.

      Parameters

      • id: string

      Returns this

    • Sets the Message-ID header. The value is wrapped in angle brackets when needed.

      Parameters

      • id: string

      Returns this

    • Uses a null reverse-path while keeping the From header.

      It is intended for bounce and other auto-generated messages. A From header is still required for a valid message.

      Returns this

    • Sets the References header for threading.

      Parameters

      • ids: string | readonly string[]

      Returns this

    • Renders a template into the message body.

      The renderer runs inside Client.send before the message is built, so it may be asynchronous. When a renderer is attached, its HTML replaces any explicit html() body, and its text replaces an explicit text() body when it produces one; an explicit subject() always wins. When both text and HTML are present after rendering, the message is sent as multipart/alternative.

      Calling this more than once replaces the previous renderer. The builder is not mutated by rendering; each send resolves it anew.

      Type Parameters

      • TInput

      Parameters

      • renderer: TemplateRenderer<TInput>

        The template renderer, for example from a plugin package.

      • input: TInput

        The template representation the renderer understands.

      Returns this

      This builder.

      Error When the renderer does not provide a render function.

      await client.send(
      new Message()
      .from("Acme <noreply@acme.example>")
      .to("customer@example.com")
      .render(renderer, { name: "Ada" }),
      );
    • Sets the Reply-To header.

      Parameters

      • address: string

      Returns this

    • Sets the Sender header, required when From contains more than one mailbox.

      Parameters

      • address: string

      Returns this

    • Sets the Subject header. Non-ASCII subjects are RFC 2047 encoded.

      Parameters

      • subject: string

      Returns this

    • Sets the plain-text body.

      When both a text and an HTML body are set, the message is sent as multipart/alternative.

      Parameters

      • body: string

      Returns this

    • Adds envelope and To header recipients.

      Parameters

      • addresses: string | readonly string[]

      Returns this