Swoosh.Email.Recipient protocol (Swoosh v1.5.0) View Source
Recipient Protocol controls how data is formatted into an email recipient
Deriving
The protocol allows leveraging the Elixir's @derive
feature to simplify protocol implementation
in trivial cases. Accepted options are:
:name
(optional):address
(required)
Example
defmodule MyUser do
@derive {Swoosh.Email.Recipient, name: :name, address: :email}
defstruct [:name, :email, :other_props]
end
or with optional name...
defmodule MySubscriber do
@derive {Swoosh.Email.Recipient, address: :email}
defstruct [:email, :preferences]
end
full implementation without deriving...
defmodule MyUser do
defstruct [:name, :email, :other_props]
end
defimpl Swoosh.Email.Recipient, for: MyUser do
def format(%MyUser{name: name, email: address} = value) do
{name, address}
end
end
Link to this section Summary
Functions
Formats value
into a Swoosh recipient, a 2-tuple with recipient name and recipient address
Link to this section Types
Specs
t() :: term()
Link to this section Functions
Specs
format(t()) :: Swoosh.Email.mailbox()
Formats value
into a Swoosh recipient, a 2-tuple with recipient name and recipient address