padrino/padrino-framework · error

To use mailers on Windows you must set a :delivery_method, s

Error message

To use mailers on Windows you must set a :delivery_method, see http://padrinorb.com/guides/features/padrino-mailer/#configuration

What it means

delivery_settings computes how mail is sent. On Unix with no explicit setting it falls back to sendmail via which sendmail. Windows has no sendmail binary, so when Gem.win_platform? is true and no :delivery_method setting exists (the settings object does not respond_to?(:delivery_method)), Padrino raises and points you at the configuration guide.

Source

Thrown at padrino-mailer/lib/padrino-mailer/helpers.rb:153

        #
        def email(mail_attributes = {}, &block)
          message = _padrino_mailer::Message.new(self)
          message.delivery_method(*delivery_settings)
          message.instance_eval(&block) if block_given?
          mail_attributes = mailer_defaults.merge(mail_attributes) if respond_to?(:mailer_defaults)
          mail_attributes.each_pair { |k, v| message.method(k).call(v) }
          message.deliver
        end

        private

        ##
        # Returns the parsed delivery method options.
        #
        def delivery_settings
          @_delivery_setting ||= begin
            if Gem.win_platform? && !respond_to?(:delivery_method)
              raise 'To use mailers on Windows you must set a :delivery_method, see http://padrinorb.com/guides/features/padrino-mailer/#configuration'
            end

            return [:sendmail, { location: `which sendmail`.chomp }] unless respond_to?(:delivery_method)
            return [delivery_method.keys[0], delivery_method.values[0]] if delivery_method.is_a?(Hash)
            return [delivery_method, {}] if delivery_method.is_a?(Symbol)
            [nil, {}]
          end
        end
      end
    end
  end
end

View on GitHub (pinned to 167044f3d5)

Solutions

  1. Set an explicit delivery method in app/mailers.rb or the app class: set :delivery_method, :smtp => { address: 'smtp.example.com', port: 587, user_name: ENV['SMTP_USER'], password: ENV['SMTP_PASS'], authentication: :plain, enable_starttls_auto: true }
  2. For tests and CI use set :delivery_method, :test so nothing real is sent
  3. If you see this on Linux, check that nothing is forcing Gem.win_platform? true (cross-compile settings, platform overrides)

Example fix

# before — app/mailers.rb sets nothing; delivering on Windows raises

# after — app/mailers.rb
set :delivery_method, :smtp => {
  address: 'smtp.example.com', port: 587,
  user_name: ENV['SMTP_USER'], password: ENV['SMTP_PASS'],
  authentication: :plain, enable_starttls_auto: true
}
Defensive patterns

Strategy: validation

Validate before calling

if Gem.win_platform? && !respond_to?(:delivery_method)
  raise 'configure set :delivery_method before delivering mail'
end

Type guard

def mail_delivery_configured?
  respond_to?(:delivery_method) && !delivery_method.nil?
end

Prevention

When it happens

Trigger: Booting or delivering mail on Windows (including JRuby on Windows or Windows CI runners) when neither the app nor the mailer sets set :delivery_method, ...; any environment where Gem.win_platform? reports true and the sendmail default cannot apply.

Common situations: Developers switching from macOS or Linux to a Windows workstation; CI suites running on windows images; deploying to Windows servers without an SMTP relay configured in the app.

Related errors


AI-assisted analysis of padrino/padrino-framework@167044f3d5 (2026-08-23). Data as JSON: /api/errors/d58976936cb4d248. Report an issue: GitHub.