diff --git a/app/controllers/admin/email_controller.rb b/app/controllers/admin/email_controller.rb
index 350facf9a..7353fc2a3 100644
--- a/app/controllers/admin/email_controller.rb
+++ b/app/controllers/admin/email_controller.rb
@@ -30,7 +30,7 @@ class Admin::EmailController < Admin::AdminController
def preview_digest
params.require(:last_seen_at)
- renderer = EmailRenderer.new(UserNotifications.digest(current_user, since: params[:last_seen_at]))
+ renderer = EmailRenderer.new(UserNotifications.digest(current_user, since: params[:last_seen_at]), html_template: true)
render json: MultiJson.dump(html_content: renderer.html, text_content: renderer.text)
end
diff --git a/app/views/email/template.html.erb b/app/views/email/template.html.erb
index fc2c2a225..dfee8d6dd 100644
--- a/app/views/email/template.html.erb
+++ b/app/views/email/template.html.erb
@@ -1,4 +1,4 @@
-
+
@@ -6,7 +6,7 @@
|
-
+ |
<%= raw(html_body) %>
|
diff --git a/lib/email_renderer.rb b/lib/email_renderer.rb
index e2cc6fc9f..178ee0157 100644
--- a/lib/email_renderer.rb
+++ b/lib/email_renderer.rb
@@ -2,28 +2,35 @@ require_dependency 'email_styles'
class EmailRenderer
- def initialize(message)
+ def initialize(message, opts=nil)
@message = message
+ @opts = opts || {}
end
def text
@text ||= @message.body.to_s.force_encoding('UTF-8')
end
- def html
- formatted_body = EmailStyles.new(PrettyText.cook(text, environment: 'email')).format
-
+ def logo_url
logo_url = SiteSetting.logo_url
if logo_url !~ /http(s)?\:\/\//
logo_url = "#{Discourse.base_url}#{logo_url}"
end
+ logo_url
+ end
- ActionView::Base.new(Rails.configuration.paths["app/views"]).render(
- template: 'email/template',
- format: :html,
- locals: { html_body: formatted_body,
- logo_url: logo_url }
- )
+ def html
+ formatted_body = EmailStyles.new(PrettyText.cook(text, environment: 'email')).format
+
+ if @opts[:html_template]
+ ActionView::Base.new(Rails.configuration.paths["app/views"]).render(
+ template: 'email/template',
+ format: :html,
+ locals: { html_body: formatted_body, logo_url: logo_url }
+ )
+ else
+ formatted_body
+ end
end
end
diff --git a/lib/email_sender.rb b/lib/email_sender.rb
index c04aad78e..6e6613b02 100644
--- a/lib/email_sender.rb
+++ b/lib/email_sender.rb
@@ -22,7 +22,14 @@ class EmailSender
return if @message.body.blank?
@message.charset = 'UTF-8'
- renderer = EmailRenderer.new(@message)
+
+ opts = {}
+
+ # Only use the html template on digest emails
+ opts[:html_template] = true if (@email_type == 'digest')
+
+ renderer = EmailRenderer.new(@message, opts)
+
@message.html_part = Mail::Part.new do
content_type 'text/html; charset=UTF-8'
body renderer.html