2015-12-14 16:09:20 +01:00
|
|
|
|
class ApplicationMailer < ActionMailer::Base
|
2019-06-21 09:50:33 +02:00
|
|
|
|
helper :application # gives access to all helpers defined within `application_helper`.
|
2020-07-23 15:09:47 +02:00
|
|
|
|
default from: "#{APPLICATION_NAME} <#{CONTACT_EMAIL}>"
|
2015-12-14 16:09:20 +01:00
|
|
|
|
layout 'mailer'
|
2019-07-17 14:41:37 +02:00
|
|
|
|
|
2022-10-20 14:19:21 +02:00
|
|
|
|
before_action :add_dolist_header
|
|
|
|
|
|
2020-02-20 11:39:33 +01:00
|
|
|
|
# Don’t retry to send a message if the server rejects the recipient address
|
|
|
|
|
rescue_from Net::SMTPSyntaxError do |_error|
|
|
|
|
|
message.perform_deliveries = false
|
|
|
|
|
end
|
|
|
|
|
|
2020-07-13 15:21:12 +02:00
|
|
|
|
rescue_from Net::SMTPServerBusy do |error|
|
2020-09-24 15:12:21 +02:00
|
|
|
|
if /unexpected recipients/.match?(error.message)
|
2020-07-13 15:21:12 +02:00
|
|
|
|
message.perform_deliveries = false
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-07-17 14:41:37 +02:00
|
|
|
|
# Attach the procedure logo to the email (if any).
|
|
|
|
|
# Returns the attachment url.
|
|
|
|
|
def attach_logo(procedure)
|
2019-08-28 13:11:58 +02:00
|
|
|
|
if procedure.logo.attached?
|
|
|
|
|
logo_filename = procedure.logo.filename.to_s
|
|
|
|
|
attachments.inline[logo_filename] = procedure.logo.download
|
2019-08-28 14:27:41 +02:00
|
|
|
|
attachments[logo_filename].url
|
2019-07-17 14:41:37 +02:00
|
|
|
|
end
|
2019-08-28 13:11:58 +02:00
|
|
|
|
|
|
|
|
|
rescue StandardError => e
|
|
|
|
|
# A problem occured when reading logo, maybe the logo is missing and we should clean the procedure to remove logo reference ?
|
2021-01-28 14:49:22 +01:00
|
|
|
|
Sentry.capture_exception(e, extra: { procedure_id: procedure.id })
|
2019-08-28 13:11:58 +02:00
|
|
|
|
nil
|
2019-07-17 14:41:37 +02:00
|
|
|
|
end
|
2022-10-20 14:19:21 +02:00
|
|
|
|
|
|
|
|
|
# mandatory for dolist
|
|
|
|
|
# used for tracking in Dolist UI
|
|
|
|
|
# the delivery_method is yet unknown (:balancer)
|
|
|
|
|
# so we add the dolist header for everyone
|
|
|
|
|
def add_dolist_header
|
|
|
|
|
headers['X-Dolist-Message-Name'] = action_name
|
|
|
|
|
end
|
2015-12-14 16:09:20 +01:00
|
|
|
|
end
|