Custom Mailer Setup In Rails

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:

  1. Write a class that responds to the actual deliver! method of ActionMailer.
  2. Register this new mailer class in ActionMailer::Base.
  3. Update the config.delivery_methodin thedevelopment.rb and production.rb config files.
steps for adding custom delivery method

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.

--

--

Huzefa S Biyawarwala

Ruby On Rails | MongoDB | ReactJS | AWS | Freelance Consultant