-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1cfcaa9
commit 51a1ab1
Showing
12 changed files
with
94 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,49 @@ | ||
defmodule Phoenix00.Mailer do | ||
use Swoosh.Mailer, otp_app: :phoenix_00 | ||
|
||
def to_map(%Swoosh.Email{} = email) do | ||
%{ | ||
"to" => contact_to_map(email.to), | ||
"from" => contact_to_map(email.from), | ||
"subject" => email.subject, | ||
"text_body" => email.text_body, | ||
"html_body" => email.html_body | ||
} | ||
end | ||
|
||
def from_map(args) do | ||
%{ | ||
"to" => to, | ||
"from" => from, | ||
"subject" => subject, | ||
"text_body" => text_body, | ||
"html_body" => html_body | ||
} = args | ||
|
||
opts = [ | ||
to: map_to_contact(to), | ||
from: map_to_contact(from), | ||
subject: subject, | ||
text_body: text_body, | ||
html_body: html_body | ||
] | ||
|
||
Swoosh.Email.new(opts) |> Swoosh.Email.put_provider_option(:configuration_set_name, "default") | ||
end | ||
|
||
defp contact_to_map(info) when is_list(info) do | ||
Enum.map(info, &contact_to_map/1) | ||
end | ||
|
||
defp contact_to_map({name, email}) do | ||
%{"name" => name, "email" => email} | ||
end | ||
|
||
defp map_to_contact(info) when is_list(info) do | ||
Enum.map(info, &map_to_contact/1) | ||
end | ||
|
||
defp map_to_contact(%{"name" => name, "email" => email}) do | ||
{name, email} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
defmodule Phoenix00.Workers.SendEmail do | ||
use Oban.Worker, queue: :default | ||
|
||
alias Phoenix00.Mailer | ||
|
||
@impl Oban.Worker | ||
def perform(%Oban.Job{args: %{"email" => email_args}}) do | ||
with email <- Mailer.from_map(email_args), | ||
{:ok, _metadata} <- Mailer.deliver(email) do | ||
:ok | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
priv/repo/migrations/20240524230521_add_oban_jobs_table.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
defmodule Phoenix00.Repo.Migrations.AddObanJobsTable do | ||
use Ecto.Migration | ||
|
||
def up do | ||
Oban.Migration.up(version: 12) | ||
end | ||
|
||
# We specify `version: 1` in `down`, ensuring that we'll roll all the way back down if | ||
# necessary, regardless of which version we've migrated `up` to. | ||
def down do | ||
Oban.Migration.down(version: 1) | ||
end | ||
end |