mardi 27 octobre 2015

Preview emails in rails with text and html

In our Rails 3.2 app we have the following set up to preview emails:

examples_controller

def registration
    mail = EventMailer.registration(registration: EventRegistration.last, cache_email: false)
    return render_mail(mail)
  end

event_mailer.rb

def registration(options = {})
    @registration = options[:registration]
    @event = Event.find(@registration.event_id)
    @subject = options[:subject] || 'Your Learn Registration'

    return_email = mail(to: @registration.email, subject: @subject)

    # the email if we got it
    return_email
  end

We just added a text version of the emails, so now in app/views/event_mailer we have registration.html.erb and registration.text.erb. Before adding the text version of the email users could browse to /webmail/examples/registration and view the html version of the email. After adding the text email, that is broken.

Ideas on how to fix this? I tried setting multipart to false in the examples controller, but that did not work.

Also, here is the render_mail method...

def render_mail(mail)
    # send it through the inline style processing
    inlined_content = InlineStyle.process(mail.body.to_s,ignore_linked_stylesheets: true)
    render(:text => inlined_content, :layout => false)
  end

Aucun commentaire:

Enregistrer un commentaire