View Source Swoosh.Email.Recipient protocol (Swoosh v1.10.1)
Recipient Protocol controls how data is formatted into an email recipient
deriving
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
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
@type t() :: term()
Link to this section Functions
@spec format(t()) :: Swoosh.Email.mailbox()
Formats value
into a Swoosh recipient, a 2-tuple with recipient name and recipient address