Question

I am using griddler and sendgrid to receive emails into my rails app but when I render email.body I only get the text in the email and not the actual html styled email. I use <%= raw post.body %> and still get the same thing. Any ideas on how I can have an email body render its html version as if you would see it in Gmail or Yahoo instead of stripping it out and rendering only the text in the email. I am using Rails 4, Sendgrid, and Griddler Gem.

My email_processor.rb file to process emails:

class EmailProcessor
  def self.process(email)
  Post.create!({ body: email.body, email: email.from })
  end
end

index.html.rb

<h1>Posts</h1>

<% if @posts.count > 0 %>
  <% @posts.each do |post| %>
    <blockquote>
      <p><%= raw post.body %></p>
      <small><%= post.email %></small>
    </blockquote>
  <% end %>
<% else %>
  <p><em>Oops, doesn't look like there are any posts yet.</em></p>
<% end %>
Was it helpful?

Solution

Instead of calling email.body, you most likely should be calling email.raw_html. If this doesn't work, their documentation for Griddler suggests

Adapters

Griddler::Email expects certain parameters to be in place for proper parsing to occur. When writing an adapter, ensure that the normalized_params method of your adapter returns a hash with these keys:

:html The html body of the email, nil or empty string if not present

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top