I am implementing a email message queue. I use interceptor.
class MyInterceptor
def self.delivering_email(mail)
Email.queue(mail)
end
end
ActionMailer::Base.register_interceptor(MyInterceptor)
But this code sends email in a normal way. How do I stop the email from being sent? I will manually send emails from the queue.
Thanks.
Sam
Go to the config folder of your emails project and open environment. rb file and add the following line at the bottom of this file. It tells ActionMailer that you want to use the SMTP server. You can also set it to be :sendmail if you are using a Unix-based operating system such as Mac OS X or Linux.
Interceptor allows making any modifications to mail objects: change the subject, add cc and bcc , even modify from . It will apply these changes for the mail delivery life cycle of every email sent before it will be actually handed off to the delivery agents.
Action Mailer allows you to send emails using mailer classes and views. Mailers work very similarly to controllers.
Set Mail::Message#perform_deliveries
to false
:
class NeverDeliverInterceptor
def self.delivering_email(message)
message.perform_deliveries = false
end
end
ActionMailer::Base.register_interceptor(NeverDeliverInterceptor)
See API doc for source & other usage.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With