Files
moreminimore-chat/app/mailers/application_mailer.rb
Kunthawat Greethong f17ce89d01 [brand] rebrand to Moreminimore Chat (configurable, phase 1)
Set the default brand to Moreminimore Chat while keeping branding
configurable via the existing InstallationConfig/ENV mechanism.

- installation_config.yml: INSTALLATION_NAME/BRAND_NAME -> Moreminimore Chat,
  BRAND_URL/WIDGET_BRAND_URL -> https://www.moreminimore.com,
  TERMS/PRIVACY -> moreminimore.com, MAILER_SUPPORT_EMAIL -> contact@moreminimore.com;
  drop LOGO_DARK (single PNG logo for light+dark).
- Mailer sender defaults -> 'Moreminimore Chat Team <contact@moreminimore.com>'
  across devise.rb, application_mailer, conversation_reply_mailer,
  mail_presenter, email_address_parseable.
- Replace SVG brand assets with logo.png/logo_thumbnail.png (1000x1000);
  update onboarding, super_admin login/nav, Vue login/signup/saml, survey,
  helpcenter, widget, year-in-review to use the single PNG and Moreminimore Chat
  name; remove dark dual-logo pattern.
- manifest.json name/short_name -> Moreminimore Chat; en.yml integration copy.

Approved by independent five-key pre-commit review deleg_a733cdf4
(passed=true, security_concerns=[], logic_errors=[]). Privacy audit findings=0.
2026-08-16 08:20:13 +07:00

85 lines
2.7 KiB
Ruby

class ApplicationMailer < ActionMailer::Base
include ActionView::Helpers::SanitizeHelper
default from: ENV.fetch('MAILER_SENDER_EMAIL', 'Moreminimore Chat Team <contact@moreminimore.com>')
before_action { ensure_current_account(params.try(:[], :account)) }
around_action :switch_locale
layout 'mailer/base'
# Fetch template from Database if available
# Order: Account Specific > Installation Specific > Fallback to file
prepend_view_path ::EmailTemplate.resolver
append_view_path Rails.root.join('app/views/mailers')
helper :frontend_urls
helper do
def global_config
@global_config ||= GlobalConfig.get('BRAND_NAME', 'BRAND_URL')
end
end
rescue_from(*ExceptionList::SMTP_EXCEPTIONS, with: :handle_smtp_exceptions)
def smtp_config_set_or_development?
ENV.fetch('SMTP_ADDRESS', nil).present? || Rails.env.development?
end
private
def handle_smtp_exceptions(message)
Rails.logger.warn 'Failed to send Email'
Rails.logger.error "Exception: #{message}"
end
def send_mail_with_liquid(*args)
Rails.logger.info "Email sent to #{args[0][:to]} with subject #{args[0][:subject]}"
mail(*args) do |format|
# explored sending a multipart email containing both text type and html
# parsing the html with nokogiri will remove the links as well
# might also remove tags like b,li etc. so lets rethink about this later
# format.text { Nokogiri::HTML(render(layout: false)).text }
format.html { render }
end
end
def liquid_droppables
# Merge additional objects into this in your mailer
# liquid template handler converts these objects into drop objects
{
account: Current.account,
user: @agent,
conversation: @conversation,
inbox: @conversation&.inbox
}
end
def liquid_locals
# expose variables you want to be exposed in liquid
locals = {
global_config: GlobalConfig.get('BRAND_NAME', 'BRAND_URL'),
action_url: @action_url
}
locals.merge({ attachment_url: @attachment_url }) if @attachment_url
locals.merge({ failed_contacts: @failed_contacts, imported_contacts: @imported_contacts })
locals
end
def locale_from_account(account)
return unless account
I18n.available_locales.map(&:to_s).include?(account.locale) ? account.locale : nil
end
def ensure_current_account(account)
Current.reset
Current.account = account if account.present?
end
def switch_locale(&)
locale ||= locale_from_account(Current.account)
locale ||= I18n.default_locale
# ensure locale won't bleed into other requests
# https://guides.rubyonrails.org/i18n.html#managing-the-locale-across-requests
I18n.with_locale(locale, &)
end
end