sendgrid v1.0.2 SendGrid.Email

Email primitive for composing emails with SendGrid’s API.

Email.build()
  |> Email.put_to("test@email.com")
  |> Email.put_from("test2@email.com")
  |> Email.put_subject("Hello from Elixir")
  |> Email.put_text("Sent with Elixir")

%Email{
  to: %{ email: "test@email.com" },
  from %{ email: "test2@email.com" },
  subject: "Hello from Elixir",
  content: [%{ type: "text/plain", value: "Sent with Elixir" }],
  ...
}

Summary

Functions

Add recipients to the BCC address field. The bcc-name can be specified as the third parameter

Add recipients to the CC address field. The cc-name can be specified as the third parameter

Adds a subtitution value to be used with a template. This function replaces existing key values

Sets the to field for the email. A to-name can be passed as the third parameter

Builds an an empty email to compose on

Sets the from field for the email. The from-name can be specified as the third parameter

Sets the html content of the email

Sets the reply_to field for the email. The reply-to name can be specified as the third parameter

Sets a future date of when to send the email

Sets the subject field for the email

Uses a predefined template for the email

Sets text content of the email

Types

content :: %{type: String.t, value: String.t}
recipient :: %{email: String.t, name: String.t | nil}
substitutions :: %{optional(String.t) => String.t}
t :: %SendGrid.Email{bcc: nil | [recipient], cc: nil | [recipient], content: nil | [content], from: nil | recipient, reply_to: nil | recipient, send_at: nil | integer, subject: nil | String.t, substitutions: nil | substitutions, template_id: nil | String.t, to: nil | [recipient]}

Functions

add_bcc(email, bcc_address)

Add recipients to the BCC address field. The bcc-name can be specified as the third parameter.

Email.add_bcc(%Email{}, "test@email.com")

Email.add_bcc(%Email{}, "test@email.com", "John Doe")
add_bcc(email, bcc_address, bcc_name)
add_cc(email, cc_address)

Add recipients to the CC address field. The cc-name can be specified as the third parameter.

Email.add_cc(%Email{}, "test@email.com")

Email.add_cc(%Email{}, "test@email.com", "John Doe")
add_cc(email, cc_address, cc_name)
add_substitution(email, sub_name, sub_value)

Specs

Adds a subtitution value to be used with a template. This function replaces existing key values.

Email.add_substitution(%Email{}, "-sentIn-", "Elixir")
add_to(email, to_address)

Sets the to field for the email. A to-name can be passed as the third parameter.

Email.add_to(%Email{}, "test@email.com")

Email.add_to(%Email{}, "test@email.com", "John Doe")
add_to(email, to_address, to_name)
build()

Specs

build :: SendGrid.Email.t

Builds an an empty email to compose on.

Email.build()
# %Email{...}
put_from(email, from_address)

Sets the from field for the email. The from-name can be specified as the third parameter.

Email.put_from(%Email{}, "test@email.com")

Email.put_from(%Email{}, "test@email.com", "John Doe")
put_from(email, from_address, from_name)
put_html(email, html_body)

Sets the html content of the email.

Email.put_html(%Email{}, "<html><body><p>Sent from Elixir!</p></body></html>")
put_reply_to(email, reply_to_address)

Specs

Sets the reply_to field for the email. The reply-to name can be specified as the third parameter.

Email.put_reply_to(%Email{}, "test@email.com")

Email.put_reply_to(%Email{}, "test@email.com", "John Doe")
put_reply_to(email, reply_to_address, reply_to_name)
put_send_at(email, send_at)

Specs

put_send_at(SendGrid.Email.t, integer) :: SendGrid.Email.t

Sets a future date of when to send the email.

Email.put_send_at(%Email{}, 1409348513)
put_subject(email, subject)

Specs

Sets the subject field for the email.

Email.put_subject(%Email{}, "Hello from Elixir")
put_template(email, template_id)

Specs

Uses a predefined template for the email.

Email.put_template(%Email{}, "the_template_id")
put_text(email, text_body)

Sets text content of the email.

Email.put_text(%Email{}, "Sent from Elixir!")