Module: Mail::CheckDeliveryParams

Included in:
ActionGmailer::DeliveryMethod
Defined in:
lib/ext/check_delivery_params.rb

Class Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ext/check_delivery_params.rb', line 8

def self.included(klass)
  klass.class_eval do

    def check_params(mail)
      envelope_from = mail.return_path ||
                      mail.sender ||
                      mail.from_addrs.first
      if envelope_from.blank?
        err = 'A sender (Return-Path, Sender or From) required'
        raise ArgumentError.new(err)
      end

      destinations = mail.destinations if mail.respond_to?(:destinations)
      if destinations.blank?
        err = 'At least one recipient (To, Cc or Bcc) is required'
        raise ArgumentError.new(err)
      end

      message ||= mail.encoded if mail.respond_to?(:encoded)
      if message.blank?
        err = 'A encoded content is required'
        raise ArgumentError.new(err)
      end

      [envelope_from, destinations, message]
    end

  end
end