# Sending email with the contents in the database

**URL:** <https://www.ruby-forum.com/t/sending-email-with-the-contents-in-the-database/121053>\
**Category:** Rails\
**Created:** [November 23, 2007, 8:39am UTC](https://www.ruby-forum.com/t/sending-email-with-the-contents-in-the-database/121053 "2007-11-23T08:39:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ruchita](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/22d042/32.png) [@ruchita](https://www.ruby-forum.com/u/ruchita)\
**Post date:** [November 23, 2007, 8:39am UTC](https://www.ruby-forum.com/t/sending-email-with-the-contents-in-the-database/121053/1 "2007-11-23T08:39:32Z")

</div>

Hi all,

I am implementing the functionality where I have to send an email to the  
user with the contents already stored in the database. That i am able to  
do but the problem is the contents stored in the database have variables  
like \<%= @username %\> and i have to replace these variables with the  
values while sending the email.  
i.e I have a content called body in the database having value:  
Welcome \<%= @username%\>.

The login and password are \<%= @username %\> and \<%= @password%\>.

Now when in notifier i write

body :contents =\> content

and in the view i access it  
\<%= @contents %\>.

This sends the email with the contents with variable @username. But I  
want to replace these variables with the values of username and  
password.

Please let me know how to implement it.

Thanks,  
Ruchita.

---

<div class="post-metadata">

**Author:** ![ruchita](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/22d042/32.png) [@ruchita](https://www.ruby-forum.com/u/ruchita)\
**Post date:** [November 23, 2007, 10:43am UTC](https://www.ruby-forum.com/t/sending-email-with-the-contents-in-the-database/121053/2 "2007-11-23T10:43:10Z")

</div>

you can run the string manually through erb:

assuming your table/col is in eg @email.content

result = ERB.new(@email.content).result(binding)
