diff --git a/README.rdoc b/README.rdoc index e930ded..da3c025 100644 --- a/README.rdoc +++ b/README.rdoc @@ -18,6 +18,17 @@ This can be over-ridden if you specify a via option Pony.mail(:to => 'you@example.com', :via => :sendmail) # sends via sendmail +You can also specify options for SMTP: + + Pony.mail(:to => 'you@example.com', :via => :smtp, :smtp => { + :host => 'smtp.yourserver.com', + :port => '25', + :user => 'user', + :pass => 'pass', + :auth => :plain # :plain, :login, :cram_md5, no auth by default + :domain => "localhost.localdomain" # the HELO domain provided by the client to the server + } + == Meta Written by Adam Wiggins diff --git a/lib/.pony.rb.swp b/lib/.pony.rb.swp new file mode 100644 index 0000000..670fa48 Binary files /dev/null and b/lib/.pony.rb.swp differ diff --git a/lib/pony.rb b/lib/pony.rb index 48bb2f0..025e9f9 100644 --- a/lib/pony.rb +++ b/lib/pony.rb @@ -6,15 +6,15 @@ module Pony def self.mail(options) raise(ArgumentError, ":to is required") unless options[:to] - unless(via = options[:via].to_s).empty? - if via == 'smtp' || via == 'sendmail' - send("transport_via_#{via}", build_tmail(options)) - else - raise(ArgumentError, ":via must be either smtp or sendmail") - end - else - transport build_tmail(options) - end + unless(via = options[:via].to_s).empty? + if via == 'smtp' || via == 'sendmail' + send("transport_via_#{via}", build_tmail(options), options) + else + raise(ArgumentError, ":via must be either smtp or sendmail") + end + else + transport build_tmail(options) + end end def self.build_tmail(options) @@ -38,7 +38,7 @@ def self.transport(tmail) end end - def self.transport_via_sendmail(tmail) + def self.transport_via_sendmail(tmail, options = {}) IO.popen('-') do |pipe| if pipe pipe.write(tmail.to_s) @@ -48,8 +48,14 @@ def self.transport_via_sendmail(tmail) end end - def self.transport_via_smtp(tmail) - Net::SMTP.start('localhost') do |smtp| + def self.transport_via_smtp(tmail, options = {:smtp => {}}) + options = options[:smtp] + # Credits for Sinatra::Mailer and Rhyhann + options_array = options.empty? ? + ['localhost' ] : + [options[:host], options[:port].to_i, options[:domain], + options[:user], options[:pass], options[:auth] ] + Net::SMTP.start(*options_array) do |smtp| smtp.sendmail(tmail.to_s, tmail.from, tmail.to) end end