Module: Pony

Defined in:
lib/pony.rb

Constant Summary collapse

@@options =
{}

Class Method Summary collapse

Class Method Details

.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!')

Raises:

  • (ArgumentError)


124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/pony.rb', line 124

def self.mail(options)
  options = @@options.merge options
  raise(ArgumentError, ":to is required") unless options[:to]

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

  options = cross_reference_depricated_fields(options)

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

  deliver build_mail(options)
end

.optionsObject



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

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


112
113
114
# File 'lib/pony.rb', line 112

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