Using Different ActiveMailer Templates in v2.02

I’m making a CRM-like system, and I would like to enable users the
ability to define and send out custom emails based on a template.

I used the method outlined here:

class Postoffice < ActionMailer::Base
def welcome(name, email)
@recipients = “[email protected]
@from = params[:contact][:email]
headers “Reply-to” => “#{email}”
@subject = “Welcome to Add Three”
@sent_on =
@content_type = “text/html”

body[:name]  = name
body[:email] = email


where you define a new def for each email template you wish to send out
and then send the mail using


The problem is it requires the template, in this case
welcome.text.html.erb, to be defined within the actual controller code
(because to deliver you need to use Postoffice.deliver_).

I’d like for the CRM user to be able to define a template to use, I was
planning on using an activerecord to store the actual file where as
Emailtemplate.file could specify which actionmailer view to use, however
I’m having trouble getting the mailer_name() function to work.
mailer_name() is suppose to be able to specify which template to use and
override the default. However I’m not able to find a specific example of
how it should be used. Could anyone provide one?

Another option I thought of was storing the template in the Database and
passing the body as an argument to deliver_welcome, but I’d like to be
able to use the template system of .erb. I’d really appreciate any
suggestions fellow members could provide


bump, anyone?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs