How to send html letters using ActionMailer?

Use of rails 2.3.14

my email erb: data.html.erb:

<% @data.each do |error| %>
    <table>
        <% error.each_pair do |k, v| %>
            <tr>
                <td>
                    <%= k %>
                </td>
                <td>
                    <%= ap v %>
                </td>
            </tr>   
        <% end %>
    </table>
    <br />
<% end %>

I can receive the email, but when I do this, it displays as plain text - instead of displaying HTML.

Mailer config action:

config.action_mailer.raise_delivery_errors = true

# Send emails during development
config.action_mailer.perform_deliveries = true
ActionMailer::Base.delivery_method = :sendmail

UPDATE: should have indicated the type of content in my delivery method:

 def data(data, sent_at = Time.now)
    Time.zone = 'Eastern Time (US & Canada)'

    content_type 'text/html'
    subject     "[#{RAILS_ENV}] An error has occurred - #{Time.now.to_s("%B %d, %Y")}"
    recipients  "bugs@mydomain.com"
    from        AppConfig['from_email']
    sent_on     sent_at
    @body   =   {:data => data}
  end
+3
source share
2 answers

It seems that rails can somehow cache a text template under certain circumstances.

I just

  • A new mailer with one view, text view was generated
  • Mail tested and text sent
  • Renamed text message to html (foo.text.haml → foo.html.haml)
  • ... (boo!)
  • HTML- (bar.html.haml)
  • ( ). HTML- .
  • html- (foo). HTML-

Cray.

+1

use <% = raw k% > <% = k.html_safe% >

0

All Articles