Sendinblue email balancing using interceptor
Signed-off-by: Chaïb Martinez <chaibax@gmail.com>
This commit is contained in:
parent
91ddd157f0
commit
b2135b6576
6 changed files with 54 additions and 9 deletions
16
app/models/dynamic_smtp_settings_interceptor.rb
Normal file
16
app/models/dynamic_smtp_settings_interceptor.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
class DynamicSmtpSettingsInterceptor
|
||||
def self.delivering_email(message)
|
||||
if ENV['SENDINBLUE_BALANCING'] == 'enabled'
|
||||
if rand(0..99) < ENV['SENDINBLUE_BALANCING_VALUE'].to_i
|
||||
message.delivery_method.settings = {
|
||||
user_name: ENV['SENDINBLUE_USER_NAME'],
|
||||
password: ENV['SENDINBLUE_CLIENT_KEY'],
|
||||
address: 'smtp-relay.sendinblue.com',
|
||||
domain: 'smtp-relay.sendinblue.com',
|
||||
port: '587',
|
||||
authentication: :cram_md5
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -46,8 +46,13 @@ SENTRY_DSN_JS=""
|
|||
MATOMO_ENABLED="disabled"
|
||||
MATOMO_ID="73"
|
||||
|
||||
SENDINBLUE_ENABLED="disabled"
|
||||
SENDINBLUE_BALANCING=""
|
||||
SENDINBLUE_BALANCING_VALUE=""
|
||||
SENDINBLUE_ENABLED=""
|
||||
SENDINBLUE_CLIENT_KEY=""
|
||||
SENDINBLUE_USER_NAME=""
|
||||
|
||||
|
||||
CRISP_ENABLED="disabled"
|
||||
CRISP_CLIENT_KEY=""
|
||||
|
||||
|
|
|
@ -45,14 +45,26 @@ Rails.application.configure do
|
|||
config.assets.raise_runtime_errors = true
|
||||
|
||||
# Action Mailer settings
|
||||
config.action_mailer.delivery_method = :letter_opener_web
|
||||
# Configure default root URL for generating URLs to routes
|
||||
config.action_mailer.default_url_options = {
|
||||
host: 'localhost',
|
||||
port: 3000
|
||||
}
|
||||
# Configure default root URL for email assets
|
||||
config.action_mailer.asset_host = "http://" + ENV['APP_HOST']
|
||||
|
||||
if ENV['SENDINBLUE_ENABLED'] == 'enabled'
|
||||
config.action_mailer.delivery_method = :smtp
|
||||
config.action_mailer.smtp_settings = {
|
||||
user_name: Rails.application.secrets.sendinblue[:username],
|
||||
password: Rails.application.secrets.sendinblue[:client_key],
|
||||
address: 'smtp-relay.sendinblue.com',
|
||||
domain: 'smtp-relay.sendinblue.com',
|
||||
port: '587',
|
||||
authentication: :cram_md5
|
||||
}
|
||||
else
|
||||
config.action_mailer.delivery_method = :letter_opener_web
|
||||
config.action_mailer.default_url_options = {
|
||||
host: 'localhost',
|
||||
port: 3000
|
||||
}
|
||||
|
||||
config.action_mailer.asset_host = "http://" + ENV['APP_HOST']
|
||||
end
|
||||
|
||||
Rails.application.routes.default_url_options = {
|
||||
host: 'localhost',
|
||||
|
|
|
@ -77,6 +77,16 @@ Rails.application.configure do
|
|||
port: '2525',
|
||||
authentication: :cram_md5
|
||||
}
|
||||
elsif ENV['SENDINBLUE_ENABLED'] == 'enabled'
|
||||
config.action_mailer.delivery_method = :smtp
|
||||
config.action_mailer.smtp_settings = {
|
||||
user_name: Rails.application.secrets.sendinblue[:username],
|
||||
password: Rails.application.secrets.sendinblue[:client_key],
|
||||
address: 'smtp-relay.sendinblue.com',
|
||||
domain: 'smtp-relay.sendinblue.com',
|
||||
port: '587',
|
||||
authentication: :cram_md5
|
||||
}
|
||||
else
|
||||
config.action_mailer.delivery_method = :mailjet
|
||||
end
|
||||
|
|
1
config/initializers/dynamic_smtp_settings_interceptor.rb
Normal file
1
config/initializers/dynamic_smtp_settings_interceptor.rb
Normal file
|
@ -0,0 +1 @@
|
|||
ActionMailer::Base.register_interceptor "DynamicSmtpSettingsInterceptor"
|
|
@ -54,6 +54,7 @@ defaults: &defaults
|
|||
webhook_secret: <%= ENV['HELPSCOUT_WEBHOOK_SECRET'] %>
|
||||
sendinblue:
|
||||
enabled: <%= ENV['SENDINBLUE_ENABLED'] == 'enabled' %>
|
||||
username: <%= ENV['SENDINBLUE_USER_NAME'] %>
|
||||
client_key: <%= ENV['SENDINBLUE_CLIENT_KEY'] %>
|
||||
api_v3_key: <%= ENV['SENDINBLUE_API_V3_KEY'] %>
|
||||
matomo:
|
||||
|
|
Loading…
Reference in a new issue