GreenMail (greenmail v0.1.0)

Copy Markdown View Source

Local SMTP+IMAP email server for dev/test environments.

Wraps GreenMail — a lightweight, in-memory mail server that runs as a Java process managed by an OTP GenServer.

What it does

  • Full SMTP+IMAP server running locally
  • Per-address mailboxes — emails to alice@example.com land in that IMAP inbox
  • Auth disabled — any username/password auto-provisions an account
  • In-memory only — emails vanish on restart
  • Managed by OTP — starts/stops with your app, no orphans

Setup

  1. Add to your supervision tree (dev only):

     # application.ex
     children =
       if Mix.env() == :dev do
         [{GreenMail.Server, []}]
       else
         []
       end
  2. Point your SMTP/IMAP config at localhost:3025 / localhost:3143

  3. Emails stay local. Test the full loop.

API

GreenMail.status()    # => {:ok, %{smtp_port: 3025, imap_port: 3143, ...}}
GreenMail.stop()      # Stop server, release ports
GreenMail.start()     # Restart after manual stop
GreenMail.restart()   # Flush all mailboxes (restart)
GreenMail.running?()  # => true/false

Summary

Functions

API port (8080)

Message count for an email address

IMAP port (3143)

List messages for an email address via REST API

Purge inbox for an email address

SMTP port (3025)

Functions

api_port()

API port (8080)

count(email, opts \\ [])

Message count for an email address

imap_port()

IMAP port (3143)

messages(email, opts \\ [])

List messages for an email address via REST API

purge(email, opts \\ [])

Purge inbox for an email address

restart()

See GreenMail.Server.restart/0.

running?()

See GreenMail.Server.running?/0.

smtp_port()

SMTP port (3025)

start()

See GreenMail.Server.start/0.

status()

See GreenMail.Server.status/0.

stop()

See GreenMail.Server.stop/0.