Packages

Elixir client for SendGrid API

Current section

Files

Jump to
send_grid_sender lib send_grid_sender.ex
Raw

lib/send_grid_sender.ex

defmodule SendGridSender do
use GenServer
def start_link do
GenServer.start_link(__MODULE__, %{}, name: SendGridSender)
end
def init(state) do
{:ok, state}
end
def handle_cast({:send_mail, user_id, email_to, template_id, subject, attrs}, state) do
{:ok, _body, headers} = Mailer.send(template_id, subject, attrs, email_to, Mix.env())
{"X-Message-Id", smtp_id} =
headers
|> Enum.filter(fn {key, _} ->
"X-Message-Id" == key
end)
|> List.first()
# %{
# user_id: user_id,
# email_to: email_to,
# subject: subject,
# template_id: template_id,
# smpt_id: smtp_id
# }
{:noreply, state}
end
end