refactor(dolist): drop smtp deliver method

This commit is contained in:
Colin Darie 2023-04-27 09:50:12 +02:00
parent f7a80eb905
commit 5cc2712873
No known key found for this signature in database
GPG key ID: 4FB865FDBCA4BCC4
5 changed files with 3 additions and 29 deletions

View file

@ -1,12 +0,0 @@
module Dolist
class SMTP < ::Mail::SMTP
def deliver!(mail)
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
end

View file

@ -21,7 +21,7 @@ class EmailEvent < ApplicationRecord
}
scope :dolist, -> { dolist_smtp.or(dolist_api) }
scope :dolist_smtp, -> { where(method: 'dolist_smtp') }
scope :dolist_smtp, -> { where(method: 'dolist_smtp') } # legacy method: removable after 2023-06
scope :dolist_api, -> { where(method: 'dolist_api') }
scope :sendinblue, -> { where(method: 'sendinblue') }
scope :outdated, -> { where("created_at < ?", RETENTION_DURATION.ago) }

View file

@ -124,7 +124,7 @@ SENDINBLUE_BALANCING_VALUE="50"
# Ratio of emails sent using DoList
# When present, N % of emails will be sent using DoList
# (and the others using the default SMTP provider)
DOLIST_BALANCING_VALUE="50"
DOLIST_API_BALANCING_VALUE="50"
# Used only by a migration to choose your default regarding procedure archive dossiers after duree_conservation_dossiers_dans_ds
# DEFAULT_PROCEDURE_EXPIRES_WHEN_TERMINE_ENABLED=true

View file

@ -96,14 +96,12 @@ 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_smtp: dolist_weigth,
dolist_api: dolist_api_weight,
mailjet: 100 - (sendinblue_weigth + dolist_weigth + dolist_api_weight)
mailjet: 100 - (sendinblue_weigth + dolist_api_weight)
}
config.action_mailer.delivery_method = :balancer
end

View file

@ -1,15 +1,3 @@
ActiveSupport.on_load(:action_mailer) do
require "dolist/smtp"
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',
port: 587,
authentication: 'plain',
enable_starttls_auto: true
}
ActionMailer::Base.add_delivery_method :dolist_api, Dolist::APISender
end