demarches-normaliennes/app/mailers/application_mailer.rb
2021-01-28 19:46:36 +01:00

31 lines
1.1 KiB
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

class ApplicationMailer < ActionMailer::Base
helper :application # gives access to all helpers defined within `application_helper`.
default from: "#{APPLICATION_NAME} <#{CONTACT_EMAIL}>"
layout 'mailer'
# Dont retry to send a message if the server rejects the recipient address
rescue_from Net::SMTPSyntaxError do |_error|
message.perform_deliveries = false
end
rescue_from Net::SMTPServerBusy do |error|
if /unexpected recipients/.match?(error.message)
message.perform_deliveries = false
end
end
# Attach the procedure logo to the email (if any).
# Returns the attachment url.
def attach_logo(procedure)
if procedure.logo.attached?
logo_filename = procedure.logo.filename.to_s
attachments.inline[logo_filename] = procedure.logo.download
attachments[logo_filename].url
end
rescue StandardError => e
# A problem occured when reading logo, maybe the logo is missing and we should clean the procedure to remove logo reference ?
Sentry.capture_exception(e, extra: { procedure_id: procedure.id })
nil
end
end