2019-08-14 09:48:44 +00:00
|
|
|
class ApplicationMailer < ActionMailer::Base
|
2020-08-06 09:51:06 +00:00
|
|
|
include ActionView::Helpers::SanitizeHelper
|
|
|
|
|
2019-12-03 17:24:08 +00:00
|
|
|
default from: ENV.fetch('MAILER_SENDER_EMAIL', 'accounts@chatwoot.com')
|
2020-08-06 09:51:06 +00:00
|
|
|
before_action { ensure_current_account(params.try(:[], :account)) }
|
|
|
|
layout 'mailer/base'
|
|
|
|
# Fetch template from Database if available
|
|
|
|
# Order: Account Specific > Installation Specific > Fallback to file
|
|
|
|
prepend_view_path ::EmailTemplate.resolver
|
2020-03-01 13:36:13 +00:00
|
|
|
append_view_path Rails.root.join('app/views/mailers')
|
2019-08-25 14:29:28 +00:00
|
|
|
helper :frontend_urls
|
2020-05-11 20:01:40 +00:00
|
|
|
helper do
|
|
|
|
def global_config
|
2020-07-30 18:28:42 +00:00
|
|
|
@global_config ||= GlobalConfig.get('BRAND_NAME', 'BRAND_URL')
|
2020-05-11 20:01:40 +00:00
|
|
|
end
|
|
|
|
end
|
2020-01-23 17:29:07 +00:00
|
|
|
|
|
|
|
def smtp_config_set_or_development?
|
|
|
|
ENV.fetch('SMTP_ADDRESS', nil).present? || Rails.env.development?
|
|
|
|
end
|
2020-08-06 09:51:06 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def send_mail_with_liquid(*args)
|
|
|
|
mail(*args) do |format|
|
|
|
|
# explored sending a multipart email containg 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
|
|
|
|
{
|
2020-08-13 19:17:24 +00:00
|
|
|
account: Current.account,
|
|
|
|
user: @agent,
|
|
|
|
conversation: @conversation,
|
|
|
|
inbox: @conversation&.inbox
|
2020-08-06 09:51:06 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def liquid_locals
|
|
|
|
# expose variables you want to be exposed in liquid
|
|
|
|
{
|
|
|
|
global_config: GlobalConfig.get('INSTALLATION_NAME', 'BRAND_URL'),
|
|
|
|
action_url: @action_url
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def ensure_current_account(account)
|
|
|
|
Current.account = account if account.present?
|
|
|
|
end
|
2019-08-14 09:48:44 +00:00
|
|
|
end
|