$ show beam-community/bamboo
Bamboo is a mature, well-architected Elixir library for composing and delivering emails through adapters. It provides a clean functional API for building email structs, a powerful address normalization system via the `Bamboo.Formatter` protocol, and built-in adapters for Mailgun, Mandrill, SendGrid, local in-memory storage, and testing. The library supports background delivery, email interceptors, attachments, plug-based preview of sent emails, and comprehensive test helpers. Production code is separated from optional Phoenix view integration (extracted to bamboo_phoenix). The architecture uses behaviours for adapters and delivery strategies, making it extensible. It is actively maintained, with recent commits and CI passing on Elixir 1.17-1.19.
The LLM identified 6 files worth highlighting for reuse:
Defines the `Bamboo.Formatter` protocol for converting any data structure (e.g., user structs) into a standardized `{name, address}` tuple. Includes built-in implementations for strings, tuples, lists, and maps (with a helpful error). Pattern allows customization per address type (`from`, `to`, `cc`, `bcc`). Self-contained and reusable for any system needing flexible address formatting.
Defines the `Bamboo.Adapter` behaviour contract for email delivery. Requires implementing `deliver/2`, `handle_config/1`, and `supports_attachments?/0`. Clean, minimal interface. Can be extracted to create custom adapters for any email service (e.g., Amazon SES, Postmark).
Provides `Attachment` struct and `new/2` factory function. Handles file paths, Plug.Upload structs, MIME type detection, and optional content_id for inline images. Well-designed with clear validation. Reusable in any Elixir project needing attachment handling.
Simple `Bamboo.Interceptor` behaviour with a single `call/1` callback. Allows modifying or blocking emails before delivery (e.g., deny lists, environment-specific modifications). The pattern is clean and can be applied to other message pipelines.
Agent-based in-memory store for sent emails when using `Bamboo.LocalAdapter`. Provides `push`, `all`, `one`, `get`, `get!`, `get_id`, and `reset`. Includes helpful error exceptions for missing or multiple results. Reusable as a lightweight, testable email store.
Collection of formatting functions for the sent email viewer: escapes HTML, formats email addresses with HTML-safe separators, displays headers, and truncates subjects. Self-contained and demonstrates clean separation of presentation logic from the plug. Can be reused or adapted for other email preview UIs.