Skip to content
Browse files

Now it can handle SMTP options

  • Loading branch information...
1 parent ef20ff4 commit 5cfd6a244fc185821060de8a92486947979a316f @rhyhann rhyhann committed Nov 23, 2008
Showing with 29 additions and 12 deletions.
  1. +11 −0 README.rdoc
  2. BIN lib/.pony.rb.swp
  3. +18 −12 lib/pony.rb
View
11 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
View
BIN lib/.pony.rb.swp
Binary file not shown.
View
30 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

0 comments on commit 5cfd6a2

Please sign in to comment.
Something went wrong with that request. Please try again.