Skip to content

Commit 4730df9

Browse files
authored
Merge pull request #217 from maartenvanvliet/issues/bamboo_mailer
Add bamboo mailer guide
2 parents 1c5e87e + 07e0c31 commit 4730df9

File tree

4 files changed

+82
-41
lines changed

4 files changed

+82
-41
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ config :my_app, :pow,
239239
mailer_backend: MyAppWeb.PowMailer
240240
```
241241

242-
This mailer module will only output the mail to your log, so you can e.g. try out the reset password and email confirmation links. You should integrate the Pow mailer with your actual mailer system. For Swoosh integration, check out the [Swoosh mailer guide](guides/swoosh_mailer.md).
242+
This mailer module will only output the mail to your log, so you can e.g. try out the reset password and email confirmation links. You should integrate the Pow mailer with your actual mailer system. For Swoosh or Bamboo integration, check out the [Configuring mailer guide](guides/configuring_mailer.md).
243243

244244
#### Modify mailer templates
245245

guides/configuring_mailer.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Configuring mailer
2+
3+
You are able to configure a mailer for Pow and set it up with the library of
4+
your choice.
5+
6+
This guide shows how to setup Pow with
7+
8+
* [Swoosh](https://github.com/swoosh/swoosh)
9+
* [Bamboo](https://github.com/thoughtbot/bamboo)
10+
11+
You must first setup and configure either of these libraries before you can
12+
integrate them with Pow.
13+
14+
## Swoosh mailer
15+
16+
Set up your `WEB_PATH/pow_mailer.ex` file like so:
17+
18+
```elixir
19+
defmodule MyAppWeb.PowMailer do
20+
use Pow.Phoenix.Mailer
21+
use Swoosh.Mailer, otp_app: :my_app
22+
23+
import Swoosh.Email
24+
25+
require Logger
26+
27+
def cast(%{user: user, subject: subject, text: text, html: html}) do
28+
%Swoosh.Email{}
29+
|> to({"", user.email})
30+
|> from({"My App", "[email protected]"})
31+
|> subject(subject)
32+
|> html_body(html)
33+
|> text_body(text)
34+
end
35+
36+
def process(email) do
37+
email
38+
|> deliver()
39+
|> log_warnings()
40+
end
41+
42+
defp log_warnings({:error, reason}) do
43+
Logger.warn("Mailer backend failed with: #{inspect(reason)}")
44+
end
45+
46+
defp log_warnings({:ok, response}), do: {:ok, response}
47+
end
48+
```
49+
50+
Remember to add `mailer_backend: MyAppWeb.PowMailer` to the Pow configuration.
51+
52+
## Bamboo mailer
53+
54+
Set up your `WEB_PATH/pow_mailer.ex` file like so:
55+
56+
```elixir
57+
defmodule MyAppWeb.PowMailer do
58+
use Pow.Phoenix.Mailer
59+
use Bamboo.Mailer, otp_app: :my_app
60+
61+
import Bamboo.Email
62+
63+
require Logger
64+
65+
def cast(%{user: user, subject: subject, text: text, html: html}) do
66+
new_email
67+
|> to(user.email)
68+
|> from("[email protected]")
69+
|> subject(subject)
70+
|> html_body(html)
71+
|> text_body(text)
72+
end
73+
74+
def process(email) do
75+
deliver_now(email)
76+
end
77+
end
78+
```
79+
80+
Remember to add `mailer_backend: MyAppWeb.PowMailer` to the Pow configuration.

guides/swoosh_mailer.md

Lines changed: 0 additions & 39 deletions
This file was deleted.

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ defmodule Pow.MixProject do
7676
"CONTRIBUTING.md": [filename: "CONTRIBUTING"],
7777
"CHANGELOG.md": [filename: "CHANGELOG"],
7878
"guides/coherence_migration.md": [],
79-
"guides/swoosh_mailer.md": [],
79+
"guides/configuring_mailer.md": [],
8080
"guides/why_pow.md": [],
8181
"guides/user_roles.md": [],
8282
"guides/lock_users.md": [],

0 commit comments

Comments
 (0)