Sending emails with SideKiq fails (Job exception: :arguments expected to be an Array of individual string args )

I have setup Discourse 2.7.12 and configured it to send emails via Mailgun.

Even though the application is able to send test emails via the Administration panel, all the relevant email jobs fail at Sidekiq

Any ideas what could be the error?

Sidekiq example of error:

Jobs::CriticalUserEmail
{“type”=>“forgot_password”,
“user_id”=>4,
“email_token”=>“ca2fd58bd00511d21d04ca05da6239ad”, “current_site_id”=>“default”
}

Jobs::HandledExceptionWrapper: Wrapped ArgumentError: :arguments expected to be an Array of individual string args

Stack trace information

In the /logs i can see an error with title:

Job exception: :arguments expected to be an Array of individual string args

and stack trace:

/opt/bitnami/discourse/vendor/bundle/ruby/2.7.0/bundler/gems/mail-5b700fc95ee6/lib/mail/network/delivery_methods/sendmail.rb:53:in `initialize' /opt/bitnami/discourse/vendor/bundle/ruby/2.7.0/bundler/gems/mail-5b700fc95ee6/lib/mail/message.rb:278:in ` new’
/opt/bitnami/discourse/vendor/bundle/ruby/2.7.0/bundler/gems/mail-5b700fc95ee6/lib/mail/message.rb:278:in `delivery_method' actionmailer-6.1.3.2/lib/action_mailer/delivery_methods.rb:65:in ` wrap_delivery_behavior’
actionmailer-6.1.3.2/lib/action_mailer/delivery_methods.rb:79:in `wrap_delivery_behavior!' actionmailer-6.1.3.2/lib/action_mailer/base.rb:836:in ` mail’
/opt/bitnami/discourse/lib/email/build_email_helper.rb:8:in `build_email' /opt/bitnami/discourse/app/mailers/download_backup_mailer.rb:7:in ` send_email’
actionpack-6.1.3.2/lib/abstract_controller/base.rb:228:in `process_action' actionpack-6.1.3.2/lib/abstract_controller/callbacks.rb:42:in ` block in process_action’
activesupport-6.1.3.2/lib/active_support/callbacks.rb:98:in `run_callbacks' actionpack-6.1.3.2/lib/abstract_controller/callbacks.rb:41:in ` process_action’
actionpack-6.1.3.2/lib/abstract_controller/base.rb:165:in `process' actionmailer-6.1.3.2/lib/action_mailer/rescuable.rb:25:in ` block in process’
actionmailer-6.1.3.2/lib/action_mailer/rescuable.rb:17:in `handle_exceptions' actionmailer-6.1.3.2/lib/action_mailer/rescuable.rb:24:in ` process’
actionview-6.1.3.2/lib/action_view/rendering.rb:39:in `process' actionmailer-6.1.3.2/lib/action_mailer/base.rb:615:in ` block in process’
activesupport-6.1.3.2/lib/active_support/notifications.rb:203:in `block in instrument' activesupport-6.1.3.2/lib/active_support/notifications/instrumenter.rb:24:in ` instrument’
activesupport-6.1.3.2/lib/active_support/notifications.rb:203:in `instrument' actionmailer-6.1.3.2/lib/action_mailer/base.rb:614:in ` process’
actionmailer-6.1.3.2/lib/action_mailer/message_delivery.rb:128:in `block in processed_mailer' actionmailer-6.1.3.2/lib/action_mailer/message_delivery.rb:127:in ` tap’
actionmailer-6.1.3.2/lib/action_mailer/message_delivery.rb:127:in `processed_mailer' actionmailer-6.1.3.2/lib/action_mailer/message_delivery.rb:30:in ` **getobj** ’
/opt/bitnami/ruby/lib/ruby/2.7.0/delegate.rb:80:in `method_missing' /opt/bitnami/discourse/lib/email/sender.rb:44:in ` send’
/opt/bitnami/discourse/app/jobs/regular/download_backup_email.rb:21:in `execute' /opt/bitnami/discourse/app/jobs/base.rb:232:in ` block (2 levels) in perform’
rails_multisite-4.0.0/lib/rails_multisite/connection_management.rb:80:in `with_connection' /opt/bitnami/discourse/app/jobs/base.rb:221:in ` block in perform’
/opt/bitnami/discourse/app/jobs/base.rb:217:in `each' /opt/bitnami/discourse/app/jobs/base.rb:217:in ` perform’
sidekiq-6.2.1/lib/sidekiq/processor.rb:196:in `execute_job' sidekiq-6.2.1/lib/sidekiq/processor.rb:164:in ` block (2 levels) in process’
sidekiq-6.2.1/lib/sidekiq/middleware/chain.rb:138:in `block in invoke' /opt/bitnami/discourse/lib/sidekiq/pausable.rb:138:in ` call’
sidekiq-6.2.1/lib/sidekiq/middleware/chain.rb:140:in `block in invoke' sidekiq-6.2.1/lib/sidekiq/middleware/chain.rb:143:in ` invoke’
sidekiq-6.2.1/lib/sidekiq/processor.rb:163:in `block in process' sidekiq-6.2.1/lib/sidekiq/processor.rb:136:in ` block (6 levels) in dispatch’
sidekiq-6.2.1/lib/sidekiq/job_retry.rb:112:in `local' sidekiq-6.2.1/lib/sidekiq/processor.rb:135:in ` block (5 levels) in dispatch’
sidekiq-6.2.1/lib/sidekiq/rails.rb:14:in `block in call' activesupport-6.1.3.2/lib/active_support/execution_wrapper.rb:88:in ` wrap’
activesupport-6.1.3.2/lib/active_support/reloader.rb:72:in `block in wrap' activesupport-6.1.3.2/lib/active_support/execution_wrapper.rb:88:in ` wrap’
activesupport-6.1.3.2/lib/active_support/reloader.rb:71:in `wrap' sidekiq-6.2.1/lib/sidekiq/rails.rb:13:in ` call’
sidekiq-6.2.1/lib/sidekiq/processor.rb:131:in `block (4 levels) in dispatch' sidekiq-6.2.1/lib/sidekiq/processor.rb:257:in ` stats’
sidekiq-6.2.1/lib/sidekiq/processor.rb:126:in `block (3 levels) in dispatch' sidekiq-6.2.1/lib/sidekiq/job_logger.rb:13:in ` call’
sidekiq-6.2.1/lib/sidekiq/processor.rb:125:in `block (2 levels) in dispatch' sidekiq-6.2.1/lib/sidekiq/job_retry.rb:79:in ` global’
sidekiq-6.2.1/lib/sidekiq/processor.rb:124:in `block in dispatch' sidekiq-6.2.1/lib/sidekiq/logger.rb:11:in ` with’
sidekiq-6.2.1/lib/sidekiq/job_logger.rb:33:in `prepare' sidekiq-6.2.1/lib/sidekiq/processor.rb:123:in ` dispatch’
sidekiq-6.2.1/lib/sidekiq/processor.rb:162:in `process' sidekiq-6.2.1/lib/sidekiq/processor.rb:78:in ` process_one’
sidekiq-6.2.1/lib/sidekiq/processor.rb:68:in `run' sidekiq-6.2.1/lib/sidekiq/util.rb:43:in ` watchdog’
sidekiq-6.2.1/lib/sidekiq/util.rb:52:in `block in safe_thread’

Relevant code (mail/network/delivery_methods/sendmail.rb)

#   Mail.defaults do
  #     delivery_method :sendmail, :location => '/absolute/path/to/your/sendmail'
  #   end
  #
  # Then just deliver the email as normal:
  #
  #   Mail.deliver do
  #     to 'mikel@test.lindsaar.net'
  #     from 'ada@test.lindsaar.net'
  #     subject 'testing sendmail'
  #     body 'testing sendmail'
  #   end
  #
  # Or by calling deliver on a Mail message
  #
  #   mail = Mail.new do
  #     to 'mikel@test.lindsaar.net'
  #     from 'ada@test.lindsaar.net'
  #     subject 'testing sendmail'
  #     body 'testing sendmail'
  #   end
  #
  #   mail.deliver!
  class Sendmail
    DEFAULTS = {
      :location   => '/usr/sbin/sendmail',
      :arguments  => %w[ -i ]
    }

    attr_accessor :settings

    class DeliveryError < StandardError
    end

    def initialize(values)

      self.settings = self.class::DEFAULTS.merge(values)
      raise ArgumentError, ":arguments expected to be an Array of individual string args" if settings[:arguments].is_a?(String)
    end

It’s the initialize method that raises the exception

I fixed it by setting the SMTP parameters to the Sidekiq as well

In /opt/bitnami/scripts/discourse-env.sh

these are exported

DISCOURSE_SMTP_HOST
DISCOURSE_SMTP_ADDRESS
DISCOURSE_SMTP_PORT_NUMBER
DISCOURSE_SMTP_USER
DISCOURSE_SMTP_USER_NAME
DISCOURSE_SMTP_PASSWORD

But Sidekiq was expecting the parameters not to have the DISCOURSE_ prefix.
So adding the following fixed the problem:

export SMTP_HOST=“xxx”
export SMTP_ADDRESS=“xx”
export SMTP_PORT_NUMBER=“587”
export SMTP_USER=“xxx”
export SMTP_USER_NAME=“xxx”
export SMTP_PASSWORD=“xxx”

I am getting this error while sending test email. I tried adding smtp details in sidekiq. Note: I have deployed this on k8s. I am on version 3.0.6