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
|
@ -5,17 +5,28 @@ ActiveSupport.on_load(:action_mailer) do
|
|||
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
|
||||
|
||||
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
|
||||
|
||||
ActionMailer::Base.add_delivery_method :dolist, Dolist::SMTP
|
||||
|
||||
ActionMailer::Base.dolist_settings = {
|
||||
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',
|
||||
|
@ -23,4 +34,6 @@ ActiveSupport.on_load(:action_mailer) do
|
|||
authentication: 'plain',
|
||||
enable_starttls_auto: true
|
||||
}
|
||||
|
||||
ActionMailer::Base.add_delivery_method :dolist_api, Dolist::ApiSender
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue