 
     assert_raise RuntimeError, ~r/cannot call Bamboo.Mailer/, fn ->
       Bamboo.Mailer.deliver_later(email)
+    end
+  end
+
+  describe "attachments" do
+    defmodule AdapterWithoutAttachmentSupport do
+      def deliver(_email, _config), do: :noop
+
+      def handle_config(config), do: config
+
+      def supports_attachments?, do: false
+    end
+
+    @tag adapter: AdapterWithoutAttachmentSupport
+    test "raise if adapter does not support attachments and attachments are sent" do
+      path = Path.join(__DIR__, "../../support/attachment.docx")
+      email = new_email(to: "foo@bar.com") |> Email.put_attachment(path)
+
+      assert_raise RuntimeError, ~r/does not support attachments/, fn ->
+        Mailer.deliver_now(email)
+      end
+
+      assert_raise RuntimeError, ~r/does not support attachments/, fn ->
+        Mailer.deliver_later(email)
+      end
+    end
+
+    @tag adapter: AdapterWithoutAttachmentSupport
+    test "does not raise if no attachments are on the email" do
+      email = new_email(to: "foo@bar.com")
+      Mailer.deliver_now(email)
+    end
+
+    @tag adapter: DefaultAdapter
+    test "does not raise if adapter supports attachments" do
+      path = Path.join(__DIR__, "../../support/attachment.docx")
+      email = new_email(to: "foo@bar.com") |> Email.put_attachment(path)
+
+      Mailer.deliver_now(email)
+
+      assert_received {:deliver, _email, _config}
+    end
+  end
+
+  describe "configuration" do
+    defmodule CustomConfigAdapter do
+      def deliver(email, config) do
+        send(:mailer_test, {:deliver, email, config})
+      end
+
+      def handle_config(config) do
+        config |> Map.put(:custom_key, "Set by the adapter")
+      end
+    end
+
+    @tag adapter: CustomConfigAdapter
+    test "uses adapter's handle_config/1 to customize or validate the config" do
+      email = new_email(to: "foo@bar.com")
+
+      Mailer.deliver_now(email)
+
+      assert_received {:deliver, _email, config}
+      assert config.custom_key == "Set by the adapter"
     end
   end
 

    assert delivered_email.bcc == [converted_recipient]
  end

  test "raises an error if an address does not have a protocol implemented" do
    email = new_email(from: 1)

    assert_raise Protocol.UndefinedError, fn ->
      FooMailer.deliver_now(email)
    end
  end

  test "raises if all recipients are nil" do
    assert_raise Bamboo.NilRecipientsError, fn ->
      new_email(to: nil, cc: nil, bcc: nil) |> FooMailer.deliver_now()
    end

    assert_raise Bamboo.NilRecipientsError, fn ->
      new_email(to: {"foo", nil})
      |> FooMailer.deliver_now()
    end

    assert_raise Bamboo.NilRecipientsError, fn ->
      new_email(to: [{"foo", nil}])
      |> FooMailer.deliver_now()
    end

    assert_raise Bamboo.NilRecipientsError, fn ->
      new_email(to: [nil])
      |> FooMailer.deliver_now()
    end
  end


    user = %Bamboo.Test.User{first_name: "Paul", email: "foo@bar.com"}
    email = new_email(from: user, to: user, cc: user, bcc: user)

    Mailer.deliver_now(email)

    converted_recipient = {user.first_name, user.email}
    assert_received {:deliver, delivered_email, _}
