fix: choose dolist sender depending on the mail domain

This commit is contained in:
simon lehericey 2024-04-19 10:59:04 +02:00
parent efc1fafaab
commit 45fa700561
No known key found for this signature in database
GPG key ID: CDE670D827C7B3C5
3 changed files with 9 additions and 4 deletions

View file

@ -190,9 +190,11 @@ module Dolist
format(base, account_id: account_id)
end
def sender_id
Rails.cache.fetch("dolist_api_sender_id", expires_in: 1.hour) do
senders.dig("ItemList", 0, "Sender", "ID")
def sender_id(domain)
if domain == "demarches.gouv.fr"
Rails.application.secrets.dolist[:gouv_sender_id]
else
Rails.application.secrets.dolist[:default_sender_id]
end
end
@ -267,7 +269,7 @@ module Dolist
"Message": {
"Name": mail['X-Dolist-Message-Name'].value,
"Subject": mail.subject,
"SenderID": sender_id,
"SenderID": sender_id(mail.from_address.domain),
"ForceHttp": false, # ForceHttp : force le tracking http non sécurisé (True/False).
"Format": "html",
"DisableOpenTracking": true, # DisableOpenTracking : désactivation du tracking d'ouverture (True/False).

View file

@ -137,6 +137,7 @@ MATOMO_IFRAME_URL="https://matomo.example.org/index.php?module=CoreAdminHome&act
# DOLIST_ACCOUNT_ID=""
# DOLIST_NO_REPLY_EMAIL=""
# DOLIST_API_KEY=""
# DOLIST_DEFAULT_SENDER_ID=""
# SMTP Provider: SIB (Brevo)
# SENDINBLUE_SMTP_ADDRESS=""

View file

@ -32,6 +32,8 @@ defaults: &defaults
password: <%= ENV['DOLIST_PASSWORD'] %>
account_id: <%= ENV['DOLIST_ACCOUNT_ID'] %>
api_key: <%= ENV['DOLIST_API_KEY'] %>
default_sender_id: <%= ENV['DOLIST_DEFAULT_SENDER_ID'] || 1 %>
gouv_sender_id: <%= ENV['DOLIST_GOUV_SENDER_ID'] || 1 %>
api_entreprise:
key: <%= ENV['API_ENTREPRISE_KEY'] %>
mailtrap: