diff --git a/config/environments/production.rb b/config/environments/production.rb index 994f6c6fd..10ffe66af 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -80,12 +80,13 @@ Rails.application.configure do else sendinblue_weigth = ENV.fetch('SENDINBLUE_BALANCING_VALUE') { 0 }.to_i dolist_weigth = ENV.fetch('DOLIST_BALANCING_VALUE') { 0 }.to_i - + dolist_api_weight = ENV.fetch('DOLIST_API_BALANCING_VALUE') { 0 }.to_i ActionMailer::Base.add_delivery_method :balancer, BalancerDeliveryMethod config.action_mailer.balancer_settings = { sendinblue: sendinblue_weigth, dolist: dolist_weigth, - mailjet: 100 - (sendinblue_weigth + dolist_weigth) + dolist_api: dolist_api_weight, + mailjet: 100 - (sendinblue_weigth + dolist_weigth + dolist_api_weight) } config.action_mailer.delivery_method = :balancer end diff --git a/config/initializers/dolist.rb b/config/initializers/dolist.rb index af4ae6169..1f59a888e 100644 --- a/config/initializers/dolist.rb +++ b/config/initializers/dolist.rb @@ -5,17 +5,28 @@ ActiveSupport.on_load(:action_mailer) do mail.from(ENV['DOLIST_NO_REPLY_EMAIL']) mail.sender(ENV['DOLIST_NO_REPLY_EMAIL']) mail['X-ACCOUNT-ID'] = Rails.application.secrets.dolist[:account_id] - mail['X-Dolist-Sending-Type'] = 'TransactionalService' # send even if the target is not active super(mail) end end + + class ApiSender + def initialize(mail); end + + def deliver!(mail) + response = Dolist::API.new.send_email(mail) + if !respons&.dig("Result") + Rails.logger.info "Email not sent. Error message: #{mail}" + else + Rails.logger.info "Email sent. #{mail}" + end + end + end end - ActionMailer::Base.add_delivery_method :dolist, Dolist::SMTP - - ActionMailer::Base.dolist_settings = { + ActionMailer::Base.add_delivery_method :dolist_smtp, Dolist::SMTP + ActionMailer::Base.dolist_smtp_settings = { user_name: Rails.application.secrets.dolist[:username], password: Rails.application.secrets.dolist[:password], address: 'smtp.dolist.net', @@ -23,4 +34,6 @@ ActiveSupport.on_load(:action_mailer) do authentication: 'plain', enable_starttls_auto: true } + + ActionMailer::Base.add_delivery_method :dolist_api, Dolist::ApiSender end