Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send email asynchronously #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/phoenix_token_auth/mailer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ defmodule PhoenixTokenAuth.Mailer do
mode: Application.get_env(:phoenix_token_auth, :mailgun_mode),
test_file_path: Application.get_env(:phoenix_token_auth, :mailgun_test_file_path)

def send_email_async(email) do
Task.start fn -> send_email(email) end
end

@doc """
Sends a welcome mail to the user.
Expand All @@ -30,7 +33,7 @@ defmodule PhoenixTokenAuth.Mailer do
body = email_mod.welcome_body(user, confirmation_token)
from = Application.get_env(:phoenix_token_auth, :email_sender)

{:ok, _} = send_email(to: user.email,
{:ok, _} = send_email_async(to: user.email,
from: from,
subject: subject,
text: body)
Expand All @@ -50,7 +53,7 @@ defmodule PhoenixTokenAuth.Mailer do
body = email_mod.password_reset_body(user, reset_token)
from = Application.get_env(:phoenix_token_auth, :email_sender)

{:ok, _} = send_email(to: user.email,
{:ok, _} = send_email_async(to: user.email,
from: from,
subject: subject,
text: body)
Expand All @@ -70,7 +73,7 @@ defmodule PhoenixTokenAuth.Mailer do
body = email_mod.new_email_address_body(user, confirmation_token)
from = Application.get_env(:phoenix_token_auth, :email_sender)

{:ok, _} = send_email(to: user.unconfirmed_email,
{:ok, _} = send_email_async(to: user.unconfirmed_email,
from: from,
subject: subject,
text: body)
Expand Down