Module: Smail

Defined in:
lib/smail.rb,
lib/smail/version.rb

Constant Summary collapse

VERSION =
"0.1.2"
@@options =
{}
@@override_options =
{}
@@subject_prefix =
false
@@append_inputs =
false

Class Method Summary collapse

Class Method Details

.append_inputsObject



43
44
45
# File 'lib/smail.rb', line 43

def self.append_inputs
  @@append_inputs = true
end

.mail(options) ⇒ Object

Send an email

Smail.mail(:to => '[email protected]', :from => '[email protected]', :subject => 'hi', :body => 'Hello there.')
Smail.mail(:to => '[email protected]', :html_body => '<h1>Hello there!</h1>', :body => "In case you can't read html, Hello there.")
Smail.mail(:to => '[email protected]', :cc => '[email protected]', :from => '[email protected]', :subject => 'hi', :body => 'Howsit!')


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/smail.rb', line 51

def self.mail(options)
  if @@append_inputs
    options[:body] = "#{options[:body]}/n #{options.to_s}"
  end

  options = @@options.merge options
  options = options.merge @@override_options

  if @@subject_prefix
    options[:subject] = "#{@@subject_prefix}#{options[:subject]}"
  end

  fail ArgumentError, ':to is required' unless options[:to]

  options[:via] = default_delivery_method unless options.key?(:via)

  if options.key?(:via) && options[:via] == :sendmail
    options[:via_options] ||= {}
    options[:via_options][:location] ||= sendmail_binary
  end

  deliver build_mail(options)
end

.optionsObject



27
28
29
# File 'lib/smail.rb', line 27

def self.options()
  @@options
end

.options=(value) ⇒ Object

Default options can be set so that they don’t have to be repeated.

 Smail.options = {
       :from => '[email protected]',
       :via => :smtp,
       :via_options => {
          :host => 'smtp.yourserver.com'
       }
}
 Smail.mail(:to => 'foo@bar') # Sends mail to foo@bar from [email protected] using smtp
 Smail.mail(:from => '[email protected]', :to => 'foo@bar') # Sends mail to foo@bar from [email protected] using smtp


23
24
25
# File 'lib/smail.rb', line 23

def self.options=(value)
  @@options = value
end

.override_optionsObject



35
36
37
# File 'lib/smail.rb', line 35

def self.override_options
  @@override_options
end

.override_options=(value) ⇒ Object



31
32
33
# File 'lib/smail.rb', line 31

def self.override_options=(value)
  @@override_options = value
end

.permissable_optionsObject



75
76
77
# File 'lib/smail.rb', line 75

def self.permissable_options
  standard_options + non_standard_options
end

.subject_prefix(value) ⇒ Object



39
40
41
# File 'lib/smail.rb', line 39

def self.subject_prefix(value)
  @@subject_prefix = value
end