discourse/app/services/email_style_updater.rb
Neil Lalonde 9656a21fdb
FEATURE: customization of html emails (#7934)
This feature adds the ability to customize the HTML part of all emails using a custom HTML template and optionally some CSS to style it. The CSS will be parsed and converted into inline styles because CSS is poorly supported by email clients. When writing the custom HTML and CSS, be aware of what email clients support. Keep customizations very simple.

Customizations can be added and edited in Admin > Customize > Email Style.

Since the summary email is already heavily styled, there is a setting to disable custom styles for summary emails called "apply custom styles to digest" found in Admin > Settings > Email.

As part of this work, RTL locales are now rendered correctly for all emails.
2019-07-30 15:05:08 -04:00

39 lines
852 B
Ruby

# frozen_string_literal: true
class EmailStyleUpdater
attr_reader :errors
def initialize(user)
@user = user
@errors = []
end
def update(attrs)
if attrs.has_key?(:html)
if attrs[:html] == EmailStyle.default_template
SiteSetting.remove_override!(:email_custom_template)
else
if !attrs[:html].include?('%{email_content}')
@errors << I18n.t(
'email_style.html_missing_placeholder',
placeholder: '%{email_content}'
)
else
SiteSetting.email_custom_template = attrs[:html]
end
end
end
if attrs.has_key?(:css)
if attrs[:css] == EmailStyle.default_css
SiteSetting.remove_override!(:email_custom_css)
else
SiteSetting.email_custom_css = attrs[:css]
end
end
@errors.empty?
end
end