diff --git a/README.md b/README.md index 1364bffa..15d64d71 100644 --- a/README.md +++ b/README.md @@ -262,8 +262,8 @@ examples. ## Interceptors -It's possible to configure per Mailer interceptors. Interceptors allow -to modify / intercept (block) email on the fly. +It's possible to configure per Mailer interceptors. Interceptors allow you to +modify or block emails on the fly. ```elixir # config/config.exs @@ -273,7 +273,8 @@ config :my_app, MyApp.Mailer, end ``` -An interceptor must implement the `Bamboo.Interceptor` behaviour. To prevent email being sent, you can block it with `Bamboo.Email.block/1`. +An interceptor must implement the `Bamboo.Interceptor` behaviour. To prevent +email being sent, you can block it with `Bamboo.Email.block/1`. ```elixir # some/path/within/your/app/deny_list_interceptor.ex diff --git a/lib/bamboo/email.ex b/lib/bamboo/email.ex index b880faf5..4cadc33d 100644 --- a/lib/bamboo/email.ex +++ b/lib/bamboo/email.ex @@ -266,6 +266,16 @@ defmodule Bamboo.Email do %{email | attachments: [Bamboo.Attachment.new(path, opts) | attachments]} end + @doc ~S""" + Marks an email as blocked to prevent it from being sent out. This is meant to + be used from an interceptor. To learn more about interceptors, see the + `Bamboo.Interceptor` behaviour. + + ## Example + + iex> Bamboo.Email.block(%Bamboo.Email{blocked: false}) + %Bamboo.Email{blocked: true} + """ def block(email) do %{email | blocked: true} end diff --git a/lib/bamboo/interceptor.ex b/lib/bamboo/interceptor.ex index 0f1ca737..92275bef 100644 --- a/lib/bamboo/interceptor.ex +++ b/lib/bamboo/interceptor.ex @@ -2,7 +2,8 @@ defmodule Bamboo.Interceptor do @moduledoc ~S""" Behaviour for creating an Interceptor. - An interceptor allow to modify / block an email before it is sent. To block an email, it must be marked as intercepted with `Bamboo.Email.intercept/1`. + An interceptor allows you to modify or block an email before it is sent. To + block an email, it must be marked as blocked with `Bamboo.Email.block/1`. ## Example @@ -12,7 +13,7 @@ defmodule Bamboo.Interceptor do def call(email) do if email.to in @deny_list do - Bamboo.Email.intercept(email) + Bamboo.Email.block(email) else email end diff --git a/test/lib/bamboo/email_test.exs b/test/lib/bamboo/email_test.exs index d13965d0..f60112b1 100644 --- a/test/lib/bamboo/email_test.exs +++ b/test/lib/bamboo/email_test.exs @@ -1,5 +1,6 @@ defmodule Bamboo.EmailTest do use ExUnit.Case + doctest Bamboo.Email import Bamboo.Email