# Using Different ActiveMailer Templates in v2.02

**URL:** <https://www.ruby-forum.com/t/using-different-activemailer-templates-in-v2-02/132662>\
**Category:** Rails\
**Created:** [March 22, 2008, 8:47pm UTC](https://www.ruby-forum.com/t/using-different-activemailer-templates-in-v2-02/132662 "2008-03-22T20:47:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mfeadler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f6c823/32.png) [@mfeadler](https://www.ruby-forum.com/u/mfeadler)\
**Post date:** [March 22, 2008, 8:47pm UTC](https://www.ruby-forum.com/t/using-different-activemailer-templates-in-v2-02/132662/1 "2008-03-22T20:47:44Z")

</div>

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:

> **[【TokenPocket钱包官网】一文了解​BRC-tp冷钱包下载](https://www.jonathansng.com/ruby-on-rails/rails-send-email-tutorial/)**
>
> 一.背景1.比特币ordinals缺乏将项目分组到集合中的标准化方法，因为这依赖于特定的、通常集中的服务和钱包。目前的市场情况基本上是每个交易市场、钱包都在运行自己的server，使用自己的方法中心化

class Postoffice \< ActionMailer::Base  
def welcome(name, email)  
@recipients = “removed\_email\_address@domain.invalid”  
@from = params[:contact][:email]  
headers “Reply-to” =\> “#{email}”  
@subject = “Welcome to Add Three”  
@sent\_on = Time.now  
@content\_type = “text/html”

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

```

end  
end

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

Postoffice.deliver\_welcome(@user.name, @user.email)

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

–matt

---

<div class="post-metadata">

**Author:** ![mfeadler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f6c823/32.png) [@mfeadler](https://www.ruby-forum.com/u/mfeadler)\
**Post date:** [March 24, 2008, 7:29pm UTC](https://www.ruby-forum.com/t/using-different-activemailer-templates-in-v2-02/132662/2 "2008-03-24T19:29:50Z")

</div>

bump, anyone?
