Skip to content

Styling email content

Gleb Mazovetskiy edited this page Mar 26, 2017 · 10 revisions

NB: If you've created your app with thredded_create_app v0.1.12+, everything below has already been set up for you.

Here is how you can use roadie-rails to style the emails.

Here is a demo of what these styles look like.

First, the email template (app/views/layouts/mailer.html.erb):

<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <%= stylesheet_link_tag 'email' %>
</head>
<body>
<%= yield %>
</body>
</html>

Email styles (email.scss):

@import "variables";
// @import "thredded-coderay"; // only if you use the CodeRay plugin
@import "thredded/email";

Application mailer (app/mailers/application_mailer.rb):

class ApplicationMailer < ActionMailer::Base
  include Roadie::Rails::Automatic
  layout 'mailer'
end

Thredded initializer (config/initializers/thredded.rb):

Thredded.parent_mailer = 'ApplicationMailer'

Roadie initializer (config/initializers/roadie.rb):

Rails.application.config.roadie.before_transformation = Thredded::EmailTransformer

Production environment config (config/environments/production.rb):

config.roadie.url_options = config.action_mailer.default_url_options = {
  host: '[SET ME] example.com',
  protocol: 'https'
}
# Roadie requires this to be nil
config.action_mailer.asset_host = nil