sendmail.rb 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. # Copyright (C) 2012-2025 Zammad Foundation, https://zammad-foundation.org/
  2. class Channel::Driver::Sendmail < Channel::Driver::BaseEmailOutbound
  3. include Channel::EmailHelper
  4. # Sends a message via Sendmail
  5. def deliver(_options, attr, notification = false)
  6. # return if we run import mode
  7. return if Setting.get('import_mode')
  8. attr = prepare_message_attrs(attr)
  9. deliver_mail(attr, notification)
  10. end
  11. private
  12. # Sendmail driver is (ab)used in testing and development environments
  13. #
  14. # Normally this driver sends mails via sendmail command
  15. # The special rails test adapter is used in testing
  16. #
  17. # ZAMMAD_MAIL_TO_FILE is for debugging outgoing mails.
  18. # It allows to easily inspect contents of the outgoing messsages
  19. def deliver_mail(attr, notification)
  20. if ENV['ZAMMAD_MAIL_TO_FILE'].present?
  21. super(attr, notification, :file, { location: Rails.root.join('tmp/mails'), extension: '.eml' })
  22. elsif Rails.env.test? && ENV['ZAMMAD_MAIL_PRETEND_NOT_TEST'] != '1'
  23. # test
  24. super(attr, notification, :test)
  25. else
  26. super(attr, notification, :sendmail)
  27. end
  28. end
  29. end