LLaraNode
Mail Package

Mailables

Mailable classes provide a fluent way to build emails.

Mailables

Mailable classes provide a fluent way to build emails.

Creating Mailables

import { Mailable } from "@lara-node/mail";

class WelcomeMail extends Mailable {
  constructor(private user: User) {
    super();
  }

  build() {
    return this.to(this.user.email, this.user.name)
      .subject("Welcome to LaraNode!")
      .from("[email protected]", "LaraNode Team")
      .text(`Hello ${this.user.name}, welcome!`);
  }
}

Fluent Methods

class OrderConfirmationMail extends Mailable {
  build() {
    return this.to(this.order.user.email)
      .cc("[email protected]")
      .bcc("[email protected]")
      .replyTo("[email protected]")
      .from("[email protected]", "Orders")
      .subject(`Order #${this.order.id} Confirmed`)
      .text("Your order has been confirmed")
      .html("<h1>Order Confirmed</h1>")
      .view("emails.order-confirmation", { order: this.order })
      .attach("/path/to/invoice.pdf")
      .header("X-Custom-Header", "value")
      .priority("high")
      .tag("order");
  }
}

Simple Mailables

import { TextMailable, HtmlMailable } from "@lara-node/mail";

// Text only
const mail = new TextMailable("[email protected]", "Subject", "Body text");

// HTML only
const mail = new HtmlMailable("[email protected]", "Subject", "<h1>Hello</h1>");

Attachments

.build() {
  return this
    .to(this.user.email)
    .subject('Your Report')
    .attach('/path/to/report.pdf')
    .attach('/path/to/invoice.pdf', { as: 'invoice.pdf' })
}

Next Steps