updated Bamboo references to Swoosh; added runtime.exs config file

This commit is contained in:
Adam Piontek 2022-08-13 06:39:14 -04:00
commit d43daafdb7
11 changed files with 131 additions and 55 deletions
lib/shift73k

View file

@ -2,12 +2,19 @@ defmodule Shift73k.Accounts.UserNotifier do
alias Shift73k.Mailer
alias Shift73k.Mailer.UserEmail
def deliver(user_email, subject, body) do
%Swoosh.Email{} = email = UserEmail.compose(user_email, subject, body)
case Mailer.deliver(email) do
{:ok, msg} -> {:ok, msg, email}
err -> err
end
end
@doc """
Deliver instructions to confirm account.
"""
def deliver_confirmation_instructions(user, url) do
user
|> UserEmail.compose("Confirm Your Account", """
deliver(user.email, "Confirmation instructions", """
==============================
@ -21,15 +28,13 @@ defmodule Shift73k.Accounts.UserNotifier do
==============================
""")
|> Mailer.deliver_later()
end
@doc """
Deliver instructions to reset a user password.
"""
def deliver_reset_password_instructions(user, url) do
user
|> UserEmail.compose("Reset Your Password", """
deliver(user.email, "Reset password instructions", """
==============================
@ -43,15 +48,13 @@ defmodule Shift73k.Accounts.UserNotifier do
==============================
""")
|> Mailer.deliver_later()
end
@doc """
Deliver instructions to update a user email.
"""
def deliver_update_email_instructions(user, url) do
user
|> UserEmail.compose("Change Your E-mail", """
deliver(user.email, "Update email instructions", """
==============================
@ -65,6 +68,5 @@ defmodule Shift73k.Accounts.UserNotifier do
==============================
""")
|> Mailer.deliver_later()
end
end

View file

@ -1,3 +1,3 @@
defmodule Shift73k.Mailer do
use Bamboo.Mailer, otp_app: :shift73k
use Swoosh.Mailer, otp_app: :shift73k
end

View file

@ -1,16 +1,16 @@
defmodule Shift73k.Mailer.UserEmail do
import Bamboo.Email
import Swoosh.Email
@mailer_vars Application.compile_env(:shift73k, :app_global_vars,
mailer_reply_to: "admin@example.com",
mailer_from: {"Shift73k", "shift73k@example.com"}
)
def compose(user, subject, body_text) do
new_email()
def compose(user_email, subject, body_text) do
new()
|> from(@mailer_vars[:mailer_from])
|> to(user.email)
|> put_header("Reply-To", @mailer_vars[:mailer_reply_to])
|> to(user_email)
|> header("Reply-To", @mailer_vars[:mailer_reply_to])
|> subject(subject)
|> text_body(body_text)
end