|
24 | 24 |
|
25 | 25 | For direct usage of API
|
26 | 26 |
|
27 |
| - config :mailtrap, |
28 |
| - api_token: "PASTE TOKEN HERE" |
| 27 | +```elixir |
| 28 | +config :mailtrap, |
| 29 | + api_token: "PASTE TOKEN HERE" |
| 30 | +``` |
29 | 31 |
|
30 | 32 | For Mailtrap Sandbox Bamboo adapter
|
31 | 33 |
|
32 |
| - config :test_mailtrap, TestMailtrap.Mailer, |
33 |
| - adapter: Bamboo.MailtrapSandboxAdapter, |
34 |
| - api_token: "PASTE TOKEN HERE", |
35 |
| - inbox_id: 111 # replace with your inbox id |
| 34 | +```elixir |
| 35 | +config :test_mailtrap, TestMailtrap.Mailer, |
| 36 | + adapter: Bamboo.MailtrapSandboxAdapter, |
| 37 | + api_token: "PASTE TOKEN HERE", |
| 38 | + inbox_id: 111 # replace with your inbox id |
| 39 | +``` |
36 | 40 |
|
37 | 41 | For Mailtrap Sending Bamboo adapter
|
38 | 42 |
|
39 |
| - config :test_mailtrap, TestMailtrap.Mailer, |
40 |
| - adapter: Bamboo.MailtrapSendingAdapter, |
41 |
| - api_token: "PASTE TOKEN HERE" |
| 43 | +```elixir |
| 44 | +config :test_mailtrap, TestMailtrap.Mailer, |
| 45 | + adapter: Bamboo.MailtrapSendingAdapter, |
| 46 | + api_token: "PASTE TOKEN HERE" |
| 47 | +``` |
42 | 48 |
|
43 | 49 | ## Usage
|
44 | 50 |
|
45 | 51 | Sending to Mailtrap Sandbox API
|
46 | 52 |
|
47 |
| - client = Mailtrap.Sandbox.client("PASTE TOKEN HERE") |
48 |
| - email = (%Mailtrap.Email{} |
49 |
| - |> Mailtrap.Email.put_from({"From name", "[email protected]"}) |
50 |
| - |> Mailtrap.Email.put_to({"Recepient", "[email protected]"}) |
51 |
| - |> Mailtrap.Email.put_subject("Hi there") |
52 |
| - |> Mailtrap.Email.put_text("General Kenobi")) |
53 |
| - Mailtrap.Sandbox.send(client, email, 111) # replace 111 with your inbox id |
| 53 | +```elixir |
| 54 | +client = Mailtrap.Sandbox.client("PASTE TOKEN HERE") |
| 55 | +email = (%Mailtrap.Email{} |
| 56 | + |> Mailtrap. Email. put_from({ "From name", "[email protected]"}) |
| 57 | + |> Mailtrap. Email. put_to({ "Recepient", "[email protected]"}) |
| 58 | + |> Mailtrap.Email.put_subject("Hi there") |
| 59 | + |> Mailtrap.Email.put_text("General Kenobi")) |
| 60 | +Mailtrap.Sandbox.send(client, email, 111) # replace 111 with your inbox id |
| 61 | +``` |
54 | 62 |
|
55 | 63 | Sending via Mailtrap Sending API
|
56 | 64 |
|
57 |
| - client = Mailtrap.Sending.client("PASTE TOKEN HERE") |
58 |
| - email = (%Mailtrap.Email{} |
59 |
| - |> Mailtrap.Email.put_from({"From name", "[email protected]"}) |
60 |
| - |> Mailtrap.Email.put_to({"Recepient", "[email protected]"}) |
61 |
| - |> Mailtrap.Email.put_subject("Hi there") |
62 |
| - |> Mailtrap.Email.put_text("General Kenobi")) |
63 |
| - Mailtrap.Sending.send(client, email) |
| 65 | +```elixir |
| 66 | +client = Mailtrap.Sending.client("PASTE TOKEN HERE") |
| 67 | +email = (%Mailtrap.Email{} |
| 68 | + |> Mailtrap. Email. put_from({ "From name", "[email protected]"}) |
| 69 | + |> Mailtrap. Email. put_to({ "Recepient", "[email protected]"}) |
| 70 | + |> Mailtrap.Email.put_subject("Hi there") |
| 71 | + |> Mailtrap.Email.put_text("General Kenobi")) |
| 72 | +Mailtrap.Sending.send(client, email) |
| 73 | +``` |
64 | 74 |
|
65 | 75 | ### Bamboo adapter
|
66 | 76 |
|
67 |
| - # mailer module |
68 |
| - defmodule TestMailtrap.Mailer do |
69 |
| - use Bamboo.Mailer, otp_app: :test_mailtrap |
70 |
| - end |
71 |
| - |
72 |
| - # generate email |
73 |
| - def welcome_email(subject \\ "Hi there", friendly_name \\ "Recepient", to \\ "[email protected]") do |
74 |
| - new_email( |
75 |
| - to: {friendly_name, to}, |
76 |
| - from: {"From", "[email protected]"}, |
77 |
| - subject: subject, |
78 |
| - html_body: "<strong>Thanks for joining!</strong>", |
79 |
| - text_body: "Thanks for joining!" |
80 |
| - ) |
81 |
| - end |
82 |
| - |
83 |
| - # send |
84 |
| - welcome_email() |> TestMailtrap.Mailer.deliver_now() |
| 77 | +```elixir |
| 78 | +# mailer module |
| 79 | +defmodule TestMailtrap.Mailer do |
| 80 | + use Bamboo.Mailer, otp_app: :test_mailtrap |
| 81 | +end |
| 82 | + |
| 83 | +# generate email |
| 84 | +def welcome_email(subject \\ "Hi there", friendly_name \\ "Recepient", to \\ "[email protected]") do |
| 85 | + new_email( |
| 86 | + to: {friendly_name, to}, |
| 87 | + from: { "From", "[email protected]"}, |
| 88 | + subject: subject, |
| 89 | + html_body: "<strong>Thanks for joining!</strong>", |
| 90 | + text_body: "Thanks for joining!" |
| 91 | + ) |
| 92 | +end |
| 93 | + |
| 94 | +# send |
| 95 | +welcome_email() |> TestMailtrap.Mailer.deliver_now() |
| 96 | +``` |
85 | 97 |
|
86 | 98 | Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
|
87 | 99 | and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
|
|
0 commit comments