Merge pull request #4476 from betagouv/feat-use-sib

Activation de sendinblue
This commit is contained in:
LeSim 2019-11-06 14:01:30 +01:00 committed by GitHub
commit a21897fc08
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 56 additions and 9 deletions

View 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_SMTP_KEY'],
address: 'smtp-relay.sendinblue.com',
domain: 'smtp-relay.sendinblue.com',
port: '587',
authentication: :cram_md5
}
end
end
end
end

View file

@ -46,8 +46,14 @@ SENTRY_DSN_JS=""
MATOMO_ENABLED="disabled" MATOMO_ENABLED="disabled"
MATOMO_ID="73" MATOMO_ID="73"
SENDINBLUE_ENABLED="disabled" SENDINBLUE_BALANCING=""
SENDINBLUE_BALANCING_VALUE=""
SENDINBLUE_ENABLED=""
SENDINBLUE_CLIENT_KEY="" SENDINBLUE_CLIENT_KEY=""
SENDINBLUE_SMTP_KEY=""
SENDINBLUE_USER_NAME=""
CRISP_ENABLED="disabled" CRISP_ENABLED="disabled"
CRISP_CLIENT_KEY="" CRISP_CLIENT_KEY=""

View file

@ -45,14 +45,26 @@ Rails.application.configure do
config.assets.raise_runtime_errors = true config.assets.raise_runtime_errors = true
# Action Mailer settings # Action Mailer settings
config.action_mailer.delivery_method = :letter_opener_web
# Configure default root URL for generating URLs to routes if ENV['SENDINBLUE_ENABLED'] == 'enabled'
config.action_mailer.default_url_options = { config.action_mailer.delivery_method = :smtp
host: 'localhost', config.action_mailer.smtp_settings = {
port: 3000 user_name: Rails.application.secrets.sendinblue[:username],
} password: Rails.application.secrets.sendinblue[:smtp_key],
# Configure default root URL for email assets address: 'smtp-relay.sendinblue.com',
config.action_mailer.asset_host = "http://" + ENV['APP_HOST'] 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 = { Rails.application.routes.default_url_options = {
host: 'localhost', host: 'localhost',

View file

@ -77,6 +77,16 @@ Rails.application.configure do
port: '2525', port: '2525',
authentication: :cram_md5 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[:smtp_key],
address: 'smtp-relay.sendinblue.com',
domain: 'smtp-relay.sendinblue.com',
port: '587',
authentication: :cram_md5
}
else else
config.action_mailer.delivery_method = :mailjet config.action_mailer.delivery_method = :mailjet
end end

View file

@ -0,0 +1 @@
ActionMailer::Base.register_interceptor "DynamicSmtpSettingsInterceptor"

View file

@ -54,7 +54,9 @@ defaults: &defaults
webhook_secret: <%= ENV['HELPSCOUT_WEBHOOK_SECRET'] %> webhook_secret: <%= ENV['HELPSCOUT_WEBHOOK_SECRET'] %>
sendinblue: sendinblue:
enabled: <%= ENV['SENDINBLUE_ENABLED'] == 'enabled' %> enabled: <%= ENV['SENDINBLUE_ENABLED'] == 'enabled' %>
username: <%= ENV['SENDINBLUE_USER_NAME'] %>
client_key: <%= ENV['SENDINBLUE_CLIENT_KEY'] %> client_key: <%= ENV['SENDINBLUE_CLIENT_KEY'] %>
smtp_key: <%= ENV['SENDINBLUE_SMTP_KEY'] %>
api_v3_key: <%= ENV['SENDINBLUE_API_V3_KEY'] %> api_v3_key: <%= ENV['SENDINBLUE_API_V3_KEY'] %>
matomo: matomo:
enabled: <%= ENV['MATOMO_ENABLED'] == 'enabled' %> enabled: <%= ENV['MATOMO_ENABLED'] == 'enabled' %>