   end
   defp prepare_custom_vars(body, _email), do: body
 
+  defp prepare_attachments(body, %{attachments: []}), do: body
+  defp prepare_attachments(body, %{attachments: attachments}) do
+    Map.put(body, :attachments, Enum.map(attachments, &prepare_file(&1)))
+  end
+
+  defp prepare_file(attachment) do
+    {:file, attachment.path,
+     {"form-data",
+      [{~s/"name"/, ~s/"attachment"/},
+       {~s/"filename"/, ~s/"#{attachment.filename}"/}]},
+     []}
+  end
 
   defp prepare_from(body, %Email{from: from}), do: Map.put(body, :from, prepare_recipient(from))
 


  def deliver(%Email{} = email, config \\ []) do
    headers = prepare_headers(email, config)
    params = email |> prepare_body |> Plug.Conn.Query.encode
    url = [base_url(config), "/", config[:domain], @api_endpoint]

    case :hackney.post(url, headers, params, [:with_body]) do
      {:ok, 200, _headers, body} ->
        {:ok, %{id: Poison.decode!(body)["id"]}}
      {:ok, 401, _headers, body} ->

    |> prepare_cc(email)
    |> prepare_bcc(email)
    |> prepare_reply_to(email)
    |> prepare_attachments(email)
    |> prepare_custom_vars(email)
    |> encode_body
  end

  # example custom_vars
