# How do I stop email from being delivered in the interceptor?

**URL:** <https://www.ruby-forum.com/t/how-do-i-stop-email-from-being-delivered-in-the-interceptor/203856>\
**Category:** Rails\
**Created:** [February 28, 2011, 7:44pm UTC](https://www.ruby-forum.com/t/how-do-i-stop-email-from-being-delivered-in-the-interceptor/203856 "2011-02-28T19:44:26Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [February 28, 2011, 7:44pm UTC](https://www.ruby-forum.com/t/how-do-i-stop-email-from-being-delivered-in-the-interceptor/203856/1 "2011-02-28T19:44:26Z")

</div>

Hi,

I am developing a rails 3 application.  
I want to use a interceptor before delivering emails.  
If a conditions meets, I want to stop the email.  
How do I do that?

Thanks.

Sam

---

<div class="post-metadata">

**Author:** ![ssk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/82dd89/32.png) [@ssk](https://www.ruby-forum.com/u/ssk)\
**Post date:** [February 28, 2011, 9:24pm UTC](https://www.ruby-forum.com/t/how-do-i-stop-email-from-being-delivered-in-the-interceptor/203856/2 "2011-02-28T21:24:35Z")

</div>

On 28 February 2011 18:44, Sam K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,
> 
> I am developing a rails 3 application.  
> I want to use a interceptor before delivering emails.  
> If a conditions meets, I want to stop the email.  
> How do I do that?

When you say ‘delivering’ emails do you mean ‘sending’?.  
Is it the rails app that is sending the email?  
If so how is it initiating the send.  
Can you not just test the conditions before sending?

Colin

---

<div class="post-metadata">

**Author:** ![ssk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/82dd89/32.png) [@ssk](https://www.ruby-forum.com/u/ssk)\
**Post date:** [March 1, 2011, 1:22am UTC](https://www.ruby-forum.com/t/how-do-i-stop-email-from-being-delivered-in-the-interceptor/203856/3 "2011-03-01T01:22:31Z")

</div>

On Tue, Mar 1, 2011 at 2:44 AM, Sam K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,
> 
> I am developing a rails 3 application.  
> I want to use a interceptor before delivering emails.  
> If a conditions meets, I want to stop the email.  
> How do I do that?

Have a look at the railscast for actionmailer in rails 3. The last part  
of  
the video is about intercepting  
the emails so it gets sent to the address you specify in your config.

> To post to this group, send email to [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid).  
> To unsubscribe from this group, send email to  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid).  
> For more options, visit this group at  
> [http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).

–

---

<div class="post-metadata">

**Author:** ![ssk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/82dd89/32.png) [@ssk](https://www.ruby-forum.com/u/ssk)\
**Post date:** [April 11, 2011, 2:31pm UTC](https://www.ruby-forum.com/t/how-do-i-stop-email-from-being-delivered-in-the-interceptor/203856/4 "2011-04-11T14:31:16Z")

</div>

Sam K. wrote in post #984511:

> Hi,
> 
> I am developing a rails 3 application.  
> I want to use a interceptor before delivering emails.  
> If a conditions meets, I want to stop the email.  
> How do I do that?
> 
> Thanks.
> 
> Sam

You can throw an exception in the interceptor.

---

<div class="post-metadata">

**Author:** ![ssk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/82dd89/32.png) [@ssk](https://www.ruby-forum.com/u/ssk)\
**Post date:** [March 21, 2011, 7:24pm UTC](https://www.ruby-forum.com/t/how-do-i-stop-email-from-being-delivered-in-the-interceptor/203856/5 "2011-03-21T19:24:36Z")

</div>

Sam K. wrote in post #984511:

> Hi,
> 
> I am developing a rails 3 application.  
> I want to use a interceptor before delivering emails.  
> If a conditions meets, I want to stop the email.  
> How do I do that?
> 
> Thanks.
> 
> Sam

Sam, did you get a solution with an interceptor? I tried returning  
false but the email is still delivered.

---

<div class="post-metadata">

**Author:** ![ssk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/82dd89/32.png) [@ssk](https://www.ruby-forum.com/u/ssk)\
**Post date:** [November 4, 2011, 7:17pm UTC](https://www.ruby-forum.com/t/how-do-i-stop-email-from-being-delivered-in-the-interceptor/203856/6 "2011-11-04T19:17:34Z")

</div>

@jaden_c, I tried the “perform\_deliveries = false” in my interceptor but  
the message still sends.

class CANSPAMInterceptor  
def self.delivering\_email(message)

```
......

message.perform_deliveries = false if message.to.size == 0

```

end  
end

Is there something else I need to know?

kt

---

<div class="post-metadata">

**Author:** ![ssk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/82dd89/32.png) [@ssk](https://www.ruby-forum.com/u/ssk)\
**Post date:** [October 12, 2011, 8:28pm UTC](https://www.ruby-forum.com/t/how-do-i-stop-email-from-being-delivered-in-the-interceptor/203856/7 "2011-10-12T20:28:44Z")

</div>

I had the same problem, and stumbled upon this while reading the source  
code:

class MailInterceptor  
def self.delivering\_email(email)  
email.perform\_deliveries= false  
end  
end
