Forum: Ruby on Rails How do I stop email from being delivered in the interceptor?

Posted by Sam Kong (ssk)
on 2011-02-28 19:44
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
Posted by Colin Law (Guest)
on 2011-02-28 21:24
(Received via mailing list)
On 28 February 2011 18:44, Sam Kong <lists@ruby-forum.com> 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
Posted by Jim ruther Nill (jimboker)
on 2011-03-01 01:22
(Received via mailing list)
On Tue, Mar 1, 2011 at 2:44 AM, Sam Kong <lists@ruby-forum.com> 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 rubyonrails-talk@googlegroups.com.
> To unsubscribe from this group, send email to
> rubyonrails-talk+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>


--
Posted by Mark Nadig (digger69)
on 2011-03-21 19:24
Sam Kong 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.
Posted by Leonid Shevtsov (leonid-shevtsov)
on 2011-04-11 14:31
Sam Kong 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.
Posted by Jaden C. (jaden_c)
on 2011-10-12 20:28
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
Posted by Katie M. (katie_m)
on 2011-11-04 19:17
@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
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.