Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Markdown to text/plain and text/html for multipart email

I’m looking for a solution to send DRY multipart emails in Rails. With DRY I mean that the content for the mail is only defined once.

I’ve thought about some possible solutions but haven’t found any existing implementations.

The solutions I’ve thought about are:

  • load the text from I18n and apply Markdown for the html mail and apply Markdown with a special output type for the text mail where
    • links are put in parenthesis after the link text
    • bold, italic and other formatting that doesn't make sense are removed
    • ordered and unordered lists are maintained
  • generate only the html mail and convert that to text according to the above conditions

Is there any available solution out there? Which one is probably the better way to do it?

like image 342
fphilipe Avatar asked Sep 20 '25 07:09

fphilipe


1 Answers

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

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

If you're interested in using my sorry version of what he describes in that book, you can slap this in your Gemfile:

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

Be warned that I barely know what I'm doing, that I'm not versioning that gem, and that I probably won't really even maintain it. Frankly, I wish I could find someone else who was doing a better job, but I've been unsuccessful in doing so. If you want to fork my project and be the person doing that better job, go for it!

like image 171
chadoh Avatar answered Sep 22 '25 00:09

chadoh