@@ -2,20 +2,70 @@ defmodule SendGrid.Email do
22 @ moduledoc """
33 Email primitive for composing emails with SendGrid's API.
44
5- ## Examples
5+ You can easily compose on an Email to set the fields of your email.
6+
7+ ## Example
8+
9+ Email.build()
10+ |> Email.add_to("test@email.com")
11+ |> Email.put_from("test2@email.com")
12+ |> Email.put_subject("Hello from Elixir")
13+ |> Email.put_text("Sent with Elixir")
14+ |> SendGrid.Mailer.send()
15+
16+ ## SendGrid Specific Features
17+
18+ Many common features of SendGrid V3 API for transactional emails are supported.
19+
20+ ### Templates
21+
22+ You can use a SendGrid template by providing a template id.
23+
24+ put_template(email, "some_template_id")
25+
26+ ### Substitutions
27+
28+ You can provided a key-value pair for subsititions to have text replaced.
29+
30+ add_substitution(email, "-key-", "value")
31+
32+ ### Scheduled Sending
33+
34+ You can provide a Unix timestamp to have an email delivered in the future.
35+
36+ send_at(email, 1409348513)
37+
38+ ## Phoenix Views
39+
40+ You can use Phoenix Views to set your HTML and text content of your emails. You just have
41+ to provide a view module and template name and you're good to go! See `put_phoenix_template/3`
42+ for complete usage.
43+
44+ ### Examples
45+
46+ # Using an HTML template
47+ %Email{}
48+ |> put_phoenix_view(MyApp.Web.EmailView)
49+ |> put_phoenix_template("welcome_email.html", user: user)
50+
51+ # Using a text template
52+ %Email{}
53+ |> put_phoenix_view(MyApp.Web.EmailView)
54+ |> put_phoenix_template("welcome_email.txt", user: user)
55+
56+ # Using both an HTML and text template
57+ # Notice that there is no extension.
58+ %Email{}
59+ |> put_phoenix_view(MyApp.Web.EmailView)
60+ |> put_phoenix_template("welcome_email", user: user)
61+
62+ ### Using a Default Phoenix View
63+
64+ You can set a default Phoenix View to use for rendering templates. Just set the `:phoenix_view`
65+ config value
666
7- iex> Email.build()
8- ...> |> Email.add_to("test@email.com")
9- ...> |> Email.put_from("test2@email.com")
10- ...> |> Email.put_subject("Hello from Elixir")
11- ...> |> Email.put_text("Sent with Elixir")
12- %Email{
13- to: %{ email: "test@email.com" },
14- from %{ email: "test2@email.com" },
15- subject: "Hello from Elixir",
16- content: [%{ type: "text/plain", value: "Sent with Elixir" }],
17- ...
18- }
67+ config :sendgrid,
68+ :phoenix_view: MyApp.Web.EmailView
1969
2070 """
2171
@@ -51,13 +101,13 @@ defmodule SendGrid.Email do
51101 attachments: nil | [ attachment ] ,
52102 __phoenix_view__: nil | atom }
53103
54- @ type recipient :: % { email: String . t , name: String . t | nil }
55- @ type content :: % { type: String . t , value: String . t }
56- @ type header :: { String . t , String . t }
104+ @ type recipient :: % { email: String . t , name: String . t | nil }
105+ @ type content :: % { type: String . t , value: String . t }
106+ @ type header :: { String . t , String . t }
57107 @ type attachment :: % { content: String . t , type: String . t , filename: String . t , disposition: String . t , content_id: String . t }
58108
59- @ type substitutions :: % { String . t => String . t }
60- @ type custom_args :: % { String . t => String . t }
109+ @ type substitutions :: % { String . t => String . t }
110+ @ type custom_args :: % { String . t => String . t }
61111
62112 @ doc """
63113 Builds an an empty email to compose on.
@@ -351,7 +401,7 @@ defmodule SendGrid.Email do
351401
352402 ## Examples
353403
354- Email. put_phoenix_view(email, MyApp.Web.EmailView)
404+ put_phoenix_view(email, MyApp.Web.EmailView)
355405
356406 """
357407 @ spec put_phoenix_view ( t , atom ) :: t
@@ -383,13 +433,13 @@ defmodule SendGrid.Email do
383433
384434 ## Examples
385435
386- iex> Email. put_phoenix_template(email, "some_template.html")
436+ iex> put_phoenix_template(email, "some_template.html")
387437 %Email{content: [%{type: "text/html", value: ...}], ...}
388438
389- iex> Email. put_phoenix_template(email, "some_template.txt", name: "John Doe")
439+ iex> put_phoenix_template(email, "some_template.txt", name: "John Doe")
390440 %Email{content: [%{type: "text/plain", value: ...}], ...}
391441
392- iex> Email. put_phoenix_template(email, "some_template", user: user)
442+ iex> put_phoenix_template(email, "some_template", user: user)
393443 %Email{content: [%{type: "text/plain", value: ...}, %{type: "text/html", value: ...}], ...}
394444
395445 """
0 commit comments