Skip to content

Commit

Permalink
merged with smtp options
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Wiggins committed Jan 14, 2009
2 parents bf01bf6 + 9b78e62 commit 52f9e76
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
14 changes: 13 additions & 1 deletion README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,23 @@ 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

Patches contributed by: Mathieu Martin, Arun Thampi, Thomas Hurst, and Stephen Celis
Patches contributed by: Mathieu Martin, Arun Thampi, Thomas Hurst, Stephen
Celis, and Othmane Benkirane

Released under the MIT License: http://www.opensource.org/licenses/mit-license.php

Expand Down
15 changes: 11 additions & 4 deletions lib/pony.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def self.mail(options)
transport build_tmail(options)
else
if via_options.include?(via.to_s)
send("transport_via_#{via}", build_tmail(options))
send("transport_via_#{via}", build_tmail(options), options)
else
raise(ArgumentError, ":via must be either smtp or sendmail")
end
Expand Down Expand Up @@ -47,7 +47,7 @@ def self.via_options
%w(sendmail smtp)
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)
Expand All @@ -57,8 +57,15 @@ 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={})
options = options[:smtp] || {}

# Credits for Sinatra::Mailer
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
Expand Down

0 comments on commit 52f9e76

Please sign in to comment.