Search code examples
ruby-on-railsrubyactionmailermultipart

ActionMailer Multipart messages with Markdown


I'm trying to come up with an easy solution for creating multipart emails with ActionMailer to make life easier when writing HTML emails and also to make it easy to have a plain-text alternative. Basically, what I would like to have in an ideal world is a simple Markdown with Ruby file to render to a string and use as-is for the plain text mailer and run it through rdiscount or similar for the HTML part.


Solution

  • This is covered quite precisely in Crafting Rails Applications by José Valim. See section 4.2. If I might say, a great idea to use a more agnostic format than HTML for this specific purpose, especially due to the limited nature of HTML email.

    My only issue with this section is that it uses a format of .merb to render markdown with embedded ruby, rather than .md.erb.