Poodle.Email (poodle v1.0.0)

View Source

Email struct and validation for the Poodle SDK.

Summary

Functions

Create a new email struct.

Create a new email struct, raising on error.

Convert email struct to a map for API requests.

Validate an email struct.

Types

t()

@type t() :: %Poodle.Email{
  from: String.t(),
  html: String.t() | nil,
  subject: String.t(),
  text: String.t() | nil,
  to: String.t()
}

Functions

new(from, to, subject, opts \\ [])

@spec new(String.t(), String.t(), String.t(), keyword()) ::
  {:ok, t()} | {:error, String.t()}

Create a new email struct.

Examples

iex> Poodle.Email.new("from@example.com", "to@example.com", "Subject", html: "<h1>Hello</h1>")
{:ok, %Poodle.Email{...}}

iex> Poodle.Email.new("invalid-email", "to@example.com", "Subject")
{:error, "Invalid from email address"}

new!(from, to, subject, opts \\ [])

@spec new!(String.t(), String.t(), String.t(), keyword()) :: t()

Create a new email struct, raising on error.

Examples

iex> Poodle.Email.new!("from@example.com", "to@example.com", "Subject", html: "<h1>Hello</h1>")
%Poodle.Email{...}

to_map(email)

@spec to_map(t()) :: map()

Convert email struct to a map for API requests.

Examples

iex> email = %Poodle.Email{from: "from@example.com", to: "to@example.com", subject: "Test", html: "<h1>Hello</h1>"}
iex> Poodle.Email.to_map(email)
%{from: "from@example.com", to: "to@example.com", subject: "Test", html: "<h1>Hello</h1>"}

validate(email)

@spec validate(t()) :: :ok | {:error, String.t()}

Validate an email struct.

Examples

iex> email = %Poodle.Email{from: "from@example.com", to: "to@example.com", subject: "Test", html: "<h1>Hello</h1>"}
iex> Poodle.Email.validate(email)
:ok