Module: Pony

Defined in:
lib/pony.rb

Constant Summary collapse

@@options =
{}
@@override_options =
{}
@@subject_prefix =
false
@@append_inputs =
false

Class Method Summary collapse

Class Method Details

.append_inputsObject



137
138
139
# File 'lib/pony.rb', line 137

def self.append_inputs
  @@append_inputs = true
end

.mail(options) ⇒ Object

Send an email

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


145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/pony.rb', line 145

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



121
122
123
# File 'lib/pony.rb', line 121

def self.options()
  @@options
end

.options=(value) ⇒ Object

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

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


117
118
119
# File 'lib/pony.rb', line 117

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

.override_optionsObject



129
130
131
# File 'lib/pony.rb', line 129

def self.override_options
  @@override_options
end

.override_options=(value) ⇒ Object



125
126
127
# File 'lib/pony.rb', line 125

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

.permissable_optionsObject



169
170
171
# File 'lib/pony.rb', line 169

def self.permissable_options
  standard_options + non_standard_options
end

.subject_prefix(value) ⇒ Object



133
134
135
# File 'lib/pony.rb', line 133

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