View Source Swoosh.Adapters.Local.Storage.Memory (Swoosh v1.17.5)

In-memory storage driver used by the Swoosh.Adapters.Local module.

The emails in this mailbox are stored in memory and won't persist once your application is stopped.

Summary

Functions

List all the emails in the mailbox.

Returns a specification to start this module under a supervisor.

Delete all the emails currently in the mailbox.

Get a specific email from the mailbox.

Callback implementation for GenServer.init/1.

Pop the last email from the mailbox.

Push a new email into the mailbox.

Starts the server

Stops the server

Functions

all()

List all the emails in the mailbox.

Examples

iex> email = new |> from("tony.stark@example.com")
%Swoosh.Email{from: {"", "tony.stark@example.com"}, [...]}
iex> Memory.push(email)
%Swoosh.Email{from: {"", "tony.stark@example.com"}, headers: %{"Message-ID": "a1b2c3"}, [...]}
iex> Memory.all()
[%Swoosh.Email{from: {"", "tony.stark@example.com"}, headers: %{"Message-ID": "a1b2c3"}, [...]}]

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

delete_all()

Delete all the emails currently in the mailbox.

Examples

iex> email = new |> from("tony.stark@example.com")
%Swoosh.Email{from: {"", "tony.stark@example.com"}, [...]}
iex> Memory.push(email)
%Swoosh.Email{from: {"", "tony.stark@example.com"}, headers: %{"Message-ID": "a1b2c3"}, [...]}
iex> Memory.delete_all()
:ok
iex> Memory.all()
[]

get(id)

Get a specific email from the mailbox.

Examples

iex> email = new |> from("tony.stark@example.com")
%Swoosh.Email{from: {"", "tony.stark@example.com"}, [...]}
iex> Memory.push(email)
%Swoosh.Email{from: {"", "tony.stark@example.com"}, headers: %{"Message-ID": "a1b2c3"}, [...]}
iex> Memory.get("A1B2C3")
%Swoosh.Email{from: {"", "tony.stark@example.com"}, headers: %{"Message-ID": "a1b2c3"}, [...]}

init(args)

Callback implementation for GenServer.init/1.

pop()

Pop the last email from the mailbox.

Examples

iex> email = new |> from("tony.stark@example.com")
%Swoosh.Email{from: {"", "tony.stark@example.com"}, [...]}
iex> Memory.push(email)
%Swoosh.Email{from: {"", "tony.stark@example.com"}, headers: %{"Message-ID": "a1b2c3"}, [...]}
iex> Memory.all() |> Enum.count()
1
iex> Memory.pop()
%Swoosh.Email{from: {"", "tony.stark@example.com"}, headers: %{"Message-ID": "a1b2c3"}, [...]}
iex> Memory.all() |> Enum.count()
0

push(email)

Push a new email into the mailbox.

In order to make it easy to fetch a single email, a Message-ID header is added to the email before being stored.

Examples

iex> email = new |> from("tony.stark@example.com")
%Swoosh.Email{from: {"", "tony.stark@example.com"}, [...]}
iex> Memory.push(email)
%Swoosh.Email{from: {"", "tony.stark@example.com"}, headers: %{"Message-ID": "a1b2c3"}, [...]}

start(args \\ [])

Starts the server

stop()

Stops the server