# Using ActionMailer with template files retrieved from sql da

**URL:** <https://www.ruby-forum.com/t/using-actionmailer-with-template-files-retrieved-from-sql-da/62251>\
**Category:** Rails\
**Created:** [June 1, 2006, 10:10pm UTC](https://www.ruby-forum.com/t/using-actionmailer-with-template-files-retrieved-from-sql-da/62251 "2006-06-01T22:10:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![random52k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7bcc69/32.png) [@random52k](https://www.ruby-forum.com/u/random52k)\
**Post date:** [June 1, 2006, 10:10pm UTC](https://www.ruby-forum.com/t/using-actionmailer-with-template-files-retrieved-from-sql-da/62251/1 "2006-06-01T22:10:18Z")

</div>

I’m trying to set up a system which allows users to create and modify  
emails to send out to clients. I’ve got ActionMailer set up to send  
from a template file stored on the file system, but I’d like to be  
able to move this into the database. Does anyone know how to get  
ActionMailer to read the contents of the email from a database table  
rather than the on-disk template file? Thanks,

Mike

---

<div class="post-metadata">

**Author:** ![random52k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7bcc69/32.png) [@random52k](https://www.ruby-forum.com/u/random52k)\
**Post date:** [June 2, 2006, 12:44am UTC](https://www.ruby-forum.com/t/using-actionmailer-with-template-files-retrieved-from-sql-da/62251/2 "2006-06-02T00:44:52Z")

</div>

Hi Mike

In your class that extends ActionMailer::Base, assuming that you have a  
User class and the contents of the email you want to send is in the  
email\_contents field, use code like this:

@body = initialize\_template\_class(:user =\> user).render(:inline =\>  
user.email\_contents)

Cheers,

Cloves Carneiro Jr  
[http://re.visioni.st](http://re.visioni.st)

Mike G. wrote:

> I’m trying to set up a system which allows users to create and modify  
> emails to send out to clients. I’ve got ActionMailer set up to send  
> from a template file stored on the file system, but I’d like to be  
> able to move this into the database. Does anyone know how to get  
> ActionMailer to read the contents of the email from a database table  
> rather than the on-disk template file? Thanks,
> 
> Mike

---

<div class="post-metadata">

**Author:** ![random52k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7bcc69/32.png) [@random52k](https://www.ruby-forum.com/u/random52k)\
**Post date:** [June 2, 2006, 1:09am UTC](https://www.ruby-forum.com/t/using-actionmailer-with-template-files-retrieved-from-sql-da/62251/3 "2006-06-02T01:09:13Z")

</div>

On 2-jun-2006, at 0:44, Cloves Carneiro Jr wrote:

> Hi Mike
> 
> In your class that extends ActionMailer::Base, assuming that you  
> have a  
> User class and the contents of the email you want to send is in the  
> email\_contents field, use code like this:
> 
> @body = initialize\_template\_class(:user =\> user).render(:inline =\>  
> user.email\_contents)

Please please wiki that.

Note to the one who asked - make sure to use Liquid or Raduis or such  
because you can’t allow your users to write ERB (if you care about  
security)

–  
Julian ‘Julik’ Tarkhanov  
please send all personal mail to  
me at julik.nl
