Mark for text / plain and text / html for multi-page email

I'm looking for a solution for sending DRY multi-user emails in Rails. With DRY, I mean that content for mail is defined only once.

I thought about some possible solutions but havent found any existing implementations.

The solutions I was thinking about are as follows:

  • download text from I18n and apply Markdown for html mail and apply Markdown with custom output type for text mail where
    • links are placed in brackets after the link text
    • highlighted in bold, italic, and other formatting that don't make sense.
    • ordered and unordered lists are supported
  • only generates html mail and converts it to text according to the above conditions.

Is there a solution available? Which one is probably the best way to do this?

+2


a source to share


2 answers


In Chapter 4, Crafted Rails Applications , Jóse Valim walks you through how to make a "merb" handler that uses interspersed erb markdown and can compile text and html. Then you create a mailing generator that generates one merb template for each of your mailing actions.

You can read an excerpt from this chapter on the page where I linked you. I highly recommend buying the book.

If you're interested in using my sad version of what he describes in this book, you can tickle her in your Gemfile:



gem 'handlers', :git => "git://github.com/chadoh/handlers.git"

      

Be warned that I barely know what I am doing, that I am not running a version of this gem, and that I probably will not even support it. To be honest, I wish I could find someone else who would do better, but I was unsuccessful in this. If you want to fork my project and be the person to do it better, go for it!

+2


a source


This is PITA, but this is the only way for DRY mail so that you can support both HTML (multipart) and plaintext:

Place a copy of the html email in a partial file in the ActionMailer view directory with the following extension: _action.html.erb

Replace "action" with whatever action name you are using.

Then create 2 more files in the same directory: action.text.html.erb and action.text.plain.erb

In the text.html partial:



<%= render "action.html", :locals => {:html => true} %>

      

In the text.plain part:

<% content = render "action.html", :locals => {:html => false} %>
<%= strip_tags(content) %>

      

This works for me, although it certainly makes me want to pay monthly maintenance for madmimi

+1


a source







All Articles