defmodule Microwaveprop.Accounts.UserNotifier do @moduledoc false import Swoosh.Email alias Microwaveprop.Mailer @default_from {"NTMS Propagation", "noreply@mcintire.me"} # Delivers the email using the application mailer. defp deliver(recipient, subject, body) do email = new() |> to(recipient) |> from(from_address()) |> subject(subject) |> text_body(body) with {:ok, _metadata} <- Mailer.deliver(email) do {:ok, email} end end defp from_address do case System.get_env("EMAIL_FROM") do nil -> @default_from "" -> @default_from addr -> {"NTMS Propagation", addr} end end @doc """ Deliver instructions to confirm a newly registered account. """ def deliver_confirmation_instructions(user, url) do deliver(user.email, "Confirm your NTMS Propagation account", """ ============================== Hi #{user.callsign}, Welcome to the NTMS Propagation tool. To finish creating your account, please confirm your email by visiting the URL below: #{url} This link expires in 24 hours. If you didn't create this account, please ignore this message. ============================== """) end @doc """ Deliver instructions to update a user email. """ def deliver_update_email_instructions(user, url) do deliver(user.email, "Update email instructions", """ ============================== Hi #{user.email}, You can change your email by visiting the URL below: #{url} If you didn't request this change, please ignore this. ============================== """) end end