       |> Plug.Conn.put_resp_content_type("text/html")
       |> send_resp(:ok, email.html_body || "")
     else
-      conn 
+      conn
       |> Plug.Conn.put_resp_content_type("text/html")
-      |> render(:not_found, "email_not_found.html")
+      |> render_not_found
     end
   end
 


  get "/" do
    if Enum.empty?(all_emails()) do
      conn |> render(:ok, "no_emails.html")
    else
      conn |> render(:ok, "index.html", emails: all_emails(), selected_email: newest_email())
    end
  end

  get "/:id" do
    if email = SentEmail.get(id) do
      conn |> render(:ok, "index.html", emails: all_emails(), selected_email: email)
    else
      conn |> render(:not_found, "email_not_found.html")
    end
  end


defmodule Bamboo.EmailPreviewPlug do
  use Plug.Router
  require EEx
  alias Bamboo.SentEmail

  no_emails_template = Path.join(__DIR__, "no_emails.html.eex")
  EEx.function_from_file(:defp, :no_emails, no_emails_template)

  index_template = Path.join(__DIR__, "index.html.eex")
  EEx.function_from_file(:defp, :index, index_template, [:assigns])

  not_found_template = Path.join(__DIR__, "email_not_found.html.eex")
  EEx.function_from_file(:defp, :not_found, not_found_template, [:assigns])

  @moduledoc """
  A plug that can be used in your router to see delivered emails.
