I want to store emails into a database and then have them displayed properly in Ruby on Rails to the user (ideally with a nicely formatted, collapsible header, attachment support, etc). Is there already a good way to do this?
Right now, I store the emails to the database as a text, but I am struggling with a good way to display them to the user on the rails page?
Any suggestions? I am opening to changing the way I store the email to the database if there is a better way.
Thanks in advance!
You might want to look at the TMail library, which comes with rails (and is updateable on its own). Let’s assume you have a model called
Messagewhich corresponds to the table holding the mails, and that an attribute/column calledraw_mailholds the raw mail text.You can then instantiate an
TMAil::Mailobject and work with it like that:That provides you, e.g., with:
As far as storing the mail goes: Mails can contain non-ASCII characters, so perhaps you have to make sure that the column type chosen for
raw_mailby ActiveRecord is actually able to handle those data. I think:binaryis a good choice there.