index.community/backend/lib/mailer/user_email.ex

25 lines
680 B
Elixir
Raw Permalink Normal View History

2019-07-26 14:34:23 +00:00
defmodule Backend.Mailer.UserEmail do
2019-08-21 12:30:47 +00:00
@moduledoc """
Module for sending emails to users.
"""
2019-07-26 14:34:23 +00:00
import Swoosh.Email
2019-07-26 14:41:32 +00:00
import Backend.{Auth, Util}
2019-07-26 14:34:23 +00:00
require Logger
@spec send_login_email(String.t(), String.t()) :: {:ok | :error, term}
def send_login_email(address, domain) do
frontend_domain = get_config(:frontend_domain)
body =
"Someone tried to log in to #{domain} on https://#{frontend_domain}.\n\nIf it was you, click here to confirm:\n\n" <>
get_login_link(domain)
new()
|> to(address)
2021-07-30 16:53:51 +00:00
|> from("noreply@index.community")
|> subject("Login to index.community")
2019-07-26 14:34:23 +00:00
|> text_body(body)
|> Backend.Mailer.deliver()
end
end