amelioration(dolist): prepare l'usage de dolist par api
amelioration(email): ajoute la delivery_method dolist_api pour envoyer les mails via l'api comme recommandé par le fournisseur
This commit is contained in:
parent
f80fe9680f
commit
709a9e82a2
2 changed files with 20 additions and 6 deletions
|
@ -80,12 +80,13 @@ Rails.application.configure do
|
||||||
else
|
else
|
||||||
sendinblue_weigth = ENV.fetch('SENDINBLUE_BALANCING_VALUE') { 0 }.to_i
|
sendinblue_weigth = ENV.fetch('SENDINBLUE_BALANCING_VALUE') { 0 }.to_i
|
||||||
dolist_weigth = ENV.fetch('DOLIST_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
|
ActionMailer::Base.add_delivery_method :balancer, BalancerDeliveryMethod
|
||||||
config.action_mailer.balancer_settings = {
|
config.action_mailer.balancer_settings = {
|
||||||
sendinblue: sendinblue_weigth,
|
sendinblue: sendinblue_weigth,
|
||||||
dolist: dolist_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
|
config.action_mailer.delivery_method = :balancer
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,17 +5,28 @@ ActiveSupport.on_load(:action_mailer) do
|
||||||
mail.from(ENV['DOLIST_NO_REPLY_EMAIL'])
|
mail.from(ENV['DOLIST_NO_REPLY_EMAIL'])
|
||||||
mail.sender(ENV['DOLIST_NO_REPLY_EMAIL'])
|
mail.sender(ENV['DOLIST_NO_REPLY_EMAIL'])
|
||||||
mail['X-ACCOUNT-ID'] = Rails.application.secrets.dolist[:account_id]
|
mail['X-ACCOUNT-ID'] = Rails.application.secrets.dolist[:account_id]
|
||||||
|
|
||||||
mail['X-Dolist-Sending-Type'] = 'TransactionalService' # send even if the target is not active
|
mail['X-Dolist-Sending-Type'] = 'TransactionalService' # send even if the target is not active
|
||||||
|
|
||||||
super(mail)
|
super(mail)
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
ActionMailer::Base.add_delivery_method :dolist, Dolist::SMTP
|
ActionMailer::Base.add_delivery_method :dolist_smtp, Dolist::SMTP
|
||||||
|
ActionMailer::Base.dolist_smtp_settings = {
|
||||||
ActionMailer::Base.dolist_settings = {
|
|
||||||
user_name: Rails.application.secrets.dolist[:username],
|
user_name: Rails.application.secrets.dolist[:username],
|
||||||
password: Rails.application.secrets.dolist[:password],
|
password: Rails.application.secrets.dolist[:password],
|
||||||
address: 'smtp.dolist.net',
|
address: 'smtp.dolist.net',
|
||||||
|
@ -23,4 +34,6 @@ ActiveSupport.on_load(:action_mailer) do
|
||||||
authentication: 'plain',
|
authentication: 'plain',
|
||||||
enable_starttls_auto: true
|
enable_starttls_auto: true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ActionMailer::Base.add_delivery_method :dolist_api, Dolist::ApiSender
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue