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`.
|
2018-05-31 15:45:25 +02:00
|
|
|
default from: "demarches-simplifiees.fr <#{CONTACT_EMAIL}>"
|
2015-12-14 16:09:20 +01:00
|
|
|
layout 'mailer'
|
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)
|
|
|
|
return nil if !procedure.logo?
|
|
|
|
|
|
|
|
begin
|
2019-08-20 11:28:07 +02:00
|
|
|
if procedure.logo_active_storage.attached?
|
2019-08-28 10:42:02 +02:00
|
|
|
logo_filename = procedure.logo_active_storage.filename.to_s
|
2019-08-20 11:28:07 +02:00
|
|
|
attachments.inline[logo_filename] = procedure.logo_active_storage.download
|
|
|
|
else
|
|
|
|
logo_filename = procedure.logo.filename
|
|
|
|
attachments.inline[logo_filename] = procedure.logo.read
|
|
|
|
end
|
2019-07-17 14:41:37 +02:00
|
|
|
attachments[logo_filename].url
|
|
|
|
|
|
|
|
rescue StandardError => e
|
|
|
|
# A problem occured when reading logo, maybe the logo is missing and we should clean the procedure to remove logo reference ?
|
|
|
|
Raven.extra_context(procedure_id: procedure.id)
|
|
|
|
Raven.capture_exception(e)
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
2015-12-14 16:09:20 +01:00
|
|
|
end
|