Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- defmodule PopularApp.EmailSender do
- use GenServer
- def start_link do
- GenServer.start_link(__MODULE__, :ok, name: __MODULE__)
- end
- def init(:ok) do
- {:ok, %{last_sent: nil, last_data: nil}}
- end
- # Public API for callers - convenience wrapper around `cast`
- def send_email(data) do
- GenServer.cast(__MODULE__, {:send_email, data})
- end
- # Server functions
- def handle_cast({:send_email, data}, state) do
- data
- |> send_email()
- {:noreply, %{last_sent: calendar.local_time(), last_data: data}}
- end
- defp send_email(data) do
- # extract to, from, etc from `data`
- # send email through your provider
- end
- end
Add Comment
Please, Sign In to add comment