Initial upload

This commit is contained in:
2022-08-24 14:28:45 +02:00
parent c67653ddee
commit 57bc7b0289
370 changed files with 18479 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
defmodule Newsletter do
def read_emails(path) do
File.read!(path) |> String.split("\n", trim: true)
end
def open_log(path) do
File.open!(path, [:write])
end
def log_sent_email(pid, email) do
IO.puts(pid, "#{email}")
end
def close_log(pid) do
File.close(pid)
end
def send_newsletter(emails_path, log_path, send_fun) do
log = open_log(log_path)
read_emails(emails_path)
|> Enum.map(fn email ->
with :ok <- send_fun.(email) do
log_sent_email(log, email)
end
end)
close_log(log)
end
end