sparkpost v0.3.0 SparkPost.Content

Various message content representations.

Designed for use in %SparkPost.Transmission{content: ...}.

See submodules for concrete structs:

Summary

Functions

Create a %SparkPost.Content.Attachment from raw fields

Convenience conversions:

  • %{email_rc822: …} -> %SparkPost.Content.Raw
  • %{template_id: …, use_draft_template: …} -> %SparkPost.Content.TemplateRef
  • %{…} -> %SparkPost.Content.Inline

Functions

to_attachment(name, type, data)

Create a %SparkPost.Content.Attachment from raw fields.

Example

SparkPost.Content.to_attachment("bob.jpg", "image/jpeg", File.read!("bob.jpg"))
#=> %SparkPost.Content.Attachment{name: "bob.jpg", type: "image/jpeg", data: "iVBORw0KGgo..."}
to_content(content)

Convenience conversions:

  • %{email_rc822: …} -> %SparkPost.Content.Raw
  • %{template_id: …, use_draft_template: …} -> %SparkPost.Content.TemplateRef
  • %{…} -> %SparkPost.Content.Inline

Examples

Raw content:

SparkPost.Content.to_content(%{email_rfc822: "Content-Type: text/plain\r\nTo: \"{{address.name}}\" <{{address.email}}>\r\n\r\nThis message came from Elixir\r\n"})
#=> %SparkPost.Content.Raw{email_rfc822: "Content-Type: text/plain\r\nTo: \"{{address.name}}\" <{{address.email}}>\r\n\r\nThis message came from Elixir\r\n"}

Stored template:

SparkPost.Content.to_content(%{
  template_id: "template-101",
  use_draft_template: true
})
#=> %SparkPost.Content.TemplateRef{template_id: "template-101", use_draft_template: true}

Inline content:

Sparkpost.Content.to_content(%{
  from: "me@here.com",
  subject: "Elixir rocks",
  text: "A simple little message"
})
#=> %SparkPost.Content.Inline{
  from: "me@here.com",
  subject: "Elixir rocks",
  text: "A simple little message"
}