sendmail.rb 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Channel::Driver::Sendmail
  3. include Channel::EmailHelper
  4. def deliver(_options, attr, notification = false)
  5. # return if we run import mode
  6. return if Setting.get('import_mode')
  7. # set system_bcc of config if defined
  8. system_bcc = Setting.get('system_bcc')
  9. email_address_validation = EmailAddressValidation.new(system_bcc)
  10. if system_bcc.present? && email_address_validation.valid?
  11. attr[:bcc] ||= ''
  12. attr[:bcc] += ', ' if attr[:bcc].present?
  13. attr[:bcc] += system_bcc
  14. end
  15. attr = prepare_idn_outbound(attr)
  16. mail = Channel::EmailBuild.build(attr, notification)
  17. delivery_method(mail)
  18. mail.deliver
  19. end
  20. private
  21. def delivery_method(mail)
  22. if ENV['ZAMMAD_MAIL_TO_FILE'].present?
  23. return mail.delivery_method :file, { location: Rails.root.join('tmp/mails'), extension: '.eml' }
  24. end
  25. return mail.delivery_method :test if Rails.env.test?
  26. mail.delivery_method :sendmail
  27. end
  28. end