← Back to Projects

Mailex - Programmatic Email Generation for Elixir

A robust Elixir library for generating structured, responsive HTML and plain text emails. Inspired by Mailgen, it ensures consistent transaction emails across all clients.

·beta

Mailex

Mailex is an Elixir library designed for generating structured, responsive HTML and plain text emails with a consistent layout. Drawing inspiration from the popular Node.js library Mailgen, Mailex solves the problem of maintaining consistent email branding and layout across your application's transactional emails.

Instead of wrestling with complex HTML table structures and inline CSS for every notification, Mailex allows you to define your email content using standard Elixir maps and lists.

Features

  • Dual Output: Automatically generates both responsive HTML and plain text versions of your emails.
  • Responsive Design: Pre-tested templates that work across major email clients (Gmail, Outlook, Apple Mail, etc.).
  • Rich Content Support:
    • Custom headers and branding
    • Introduction and outro text blocks
    • Action buttons with customizable colors
    • Data tables with custom column widths and alignments
    • Key-value dictionary lists
  • Theming: Support for custom themes to match your brand identity.

Installation

Add mailex to your list of dependencies in mix.exs:

def deps do
  [
    {:mailex, git: "https://github.com/base59-dev/mailex.git", branch: "main"}
  ]
end

Usage

Generating an email is straightforward. Define your content params and pass them to Mailex.generate/1.

# Define your email content
email_params = %{
  theme: "default",
  title: "Welcome to Base59",
  product: %{
    name: "Base59 Platform",
    link: "https://base59.dev"
  },
  intro: [
    "Welcome to the platform! We're excited to have you on board.",
    "Please verify your email to get started."
  ],
  action: [
    %{
      instructions: "Click the button below to verify your account:",
      button: [
        %{
          color: "#00d4ff", # Brand color
          text: "Verify Account",
          link: "https://base59.dev/verify/123"
        }
      ]
    }
  ],
  table: [
    %{
      title: "Subscription Details",
      data: [
        %{
          item: "Pro Plan",
          description: "Monthly subscription",
          price: "$29.00"
        }
      ],
      columns: %{
        custom_alignment: %{
          price: "right"
        }
      }
    }
  ],
  outro: [
    "If you have any questions, just reply to this email."
  ]
}

# Generate the email content
{:ok, result} = Mailex.generate(email_params)

# result.html contains the responsive HTML string
# result.text contains the plain text fallback

Why Mailex?

Building HTML emails that render correctly across all devices and clients is notoriously difficult. Mailex abstracts this complexity away.

  1. Maintainability: Keep your email content separate from layout code.
  2. Consistency: Ensure every transactional email (password reset, receipt, welcome) looks exactly the same.
  3. Productivity: Spin up new email notifications in minutes, not hours.

Roadmap

  • Support for custom templates via EEx
  • Additional built-in themes
  • Dark mode support
  • Attachment handling helpers