mirror of
https://github.com/discourse/discourse.git
synced 2025-09-05 08:59:27 +08:00
restyle all user notification emails to use a custom html template
This commit is contained in:
parent
cb5ce3aab9
commit
366cb13140
7 changed files with 94 additions and 23 deletions
|
@ -6,7 +6,9 @@ module Email
|
|||
def build_email(*builder_args)
|
||||
builder = Email::MessageBuilder.new(*builder_args)
|
||||
headers(builder.header_args) if builder.header_args.present?
|
||||
mail(builder.build_args)
|
||||
mail(builder.build_args).tap { |message|
|
||||
message.html_part = builder.html_part if message
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -22,11 +24,12 @@ module Email
|
|||
user_preferences_url: "#{Discourse.base_url}/user_preferences" }.merge!(@opts)
|
||||
|
||||
if @template_args[:url].present?
|
||||
if allow_reply_by_email?
|
||||
@template_args[:respond_instructions] = I18n.t('user_notifications.reply_by_email', @template_args)
|
||||
else
|
||||
@template_args[:respond_instructions] = I18n.t('user_notifications.visit_link_to_respond', @template_args)
|
||||
end
|
||||
@template_args[:respond_instructions] =
|
||||
if allow_reply_by_email?
|
||||
I18n.t('user_notifications.reply_by_email', @template_args)
|
||||
else
|
||||
I18n.t('user_notifications.visit_link_to_respond', @template_args)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -36,6 +39,27 @@ module Email
|
|||
subject
|
||||
end
|
||||
|
||||
def html_part
|
||||
return unless html_override = @opts[:html_override]
|
||||
if @opts[:add_unsubscribe_link]
|
||||
html_override << "<br>".html_safe
|
||||
|
||||
if response_instructions = @template_args[:respond_instructions]
|
||||
html_override << PrettyText.cook(response_instructions).html_safe
|
||||
end
|
||||
|
||||
html_override << PrettyText.cook(I18n.t('unsubscribe_link', template_args)).html_safe
|
||||
end
|
||||
|
||||
styled = Email::Styles.new(html_override)
|
||||
styled.format_basic
|
||||
|
||||
Mail::Part.new do
|
||||
content_type 'text/html; charset=UTF-8'
|
||||
body styled.to_html
|
||||
end
|
||||
end
|
||||
|
||||
def body
|
||||
body = @opts[:body]
|
||||
body = I18n.t("#{@opts[:template]}.text_body_template", template_args) if @opts[:template]
|
||||
|
|
|
@ -32,14 +32,15 @@ module Email
|
|||
|
||||
renderer = Email::Renderer.new(@message, opts)
|
||||
|
||||
@message.html_part = Mail::Part.new do
|
||||
content_type 'text/html; charset=UTF-8'
|
||||
body renderer.html
|
||||
unless @message.html_part
|
||||
@message.html_part = Mail::Part.new do
|
||||
content_type 'text/html; charset=UTF-8'
|
||||
body renderer.html
|
||||
end
|
||||
end
|
||||
|
||||
@message.parts[0].body = @message.parts[0].body.to_s.gsub!(/\[\/?email-indent\]/, '')
|
||||
|
||||
|
||||
@message.text_part.content_type = 'text/plain; charset=UTF-8'
|
||||
|
||||
# Set up the email log
|
||||
|
@ -107,4 +108,4 @@ module Email
|
|||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue