Skip to content

Commit

Permalink
Add module to create email
Browse files Browse the repository at this point in the history
  • Loading branch information
erickmp07 committed Oct 22, 2021
1 parent c320772 commit eb8ae4e
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions lib/inmana/supplies/expiration_email.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
defmodule Inmana.Supplies.ExpirationEmail do
import Bamboo.Email

alias Inmana.Supply

def create(to_email, supplies) do
new_email(
to: to_email,
from: "[email protected]",
subject: "Supplies that are about to expire",
text_body: email_text(supplies)
)
end

defp email_text(supplies) do
initial_text = "------- Supplies that are about to expire: -------\n"

Enum.reduce(
supplies,
initial_text,
fn supply, text ->
text <> supply_string(supply)
end)
end

defp supply_string(%Supply{
description: description,
expiration_date: expiration_date,
responsible: responsible
}) do
"Description: #{description}, Expiration Date: #{expiration_date}, Responsible: #{responsible}\n"
end
end

0 comments on commit eb8ae4e

Please sign in to comment.