Custom Mailer Setup In Rails
Jan 26, 2021
The problem that we will address in this article:
Send an email over HTTP calls instead of SMTP delivery method in rails application but the existing code such as UserMailer.send_reset_password.deliver_now
should still work.
Solution:
We can achieve this by following 3 steps as below:
- Write a class that responds to the actual
deliver!
method of ActionMailer. - Register this new mailer class in
ActionMailer::Base
. - Update the
config.delivery_method
in thedevelopment.rb
andproduction.rb
config files.
And you are done !!! Now you will be able to send emails using your custom-defined delivery method.
Also, you don’t need to change your existing code as the above setup adds a provision to keep the existing ActionMailer
behaviour along with the custom logic to execute.
Any suggestions on above are much appreciated. Share it if you like it.