Module: Pony
- Defined in:
- lib/pony.rb
Class Method Summary collapse
- .build_tmail(options) ⇒ Object
- .mail(options) ⇒ Object
- .sendmail_binary ⇒ Object
- .transport(tmail) ⇒ Object
- .transport_via_sendmail(tmail, options = {}) ⇒ Object
- .transport_via_smtp(tmail, options = {:smtp => {}}) ⇒ Object
- .via_options ⇒ Object
Class Method Details
.build_tmail(options) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/pony.rb', line 29 def self.build_tmail() mail = TMail::Mail.new mail.to = [:to] mail.from = [:from] || 'pony@unknown' mail.subject = [:subject] mail.body = [:body] || "" mail end |
.mail(options) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/pony.rb', line 14 def self.mail() raise(ArgumentError, ":to is required") unless [:to] via = .delete(:via) if via.nil? transport build_tmail() else if .include?(via.to_s) send("transport_via_#{via}", build_tmail(), ) else raise(ArgumentError, ":via must be either smtp or sendmail") end end end |
.sendmail_binary ⇒ Object
38 39 40 |
# File 'lib/pony.rb', line 38 def self.sendmail_binary @sendmail_binary ||= `which sendmail`.chomp end |
.transport(tmail) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/pony.rb', line 42 def self.transport(tmail) if File.executable? sendmail_binary transport_via_sendmail(tmail) else transport_via_smtp(tmail) end end |
.transport_via_sendmail(tmail, options = {}) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/pony.rb', line 54 def self.transport_via_sendmail(tmail, ={}) IO.popen('-', 'w+') do |pipe| if pipe pipe.write(tmail.to_s) else exec(sendmail_binary, *tmail.to) end end end |
.transport_via_smtp(tmail, options = {:smtp => {}}) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/pony.rb', line 64 def self.transport_via_smtp(tmail, ={:smtp => {}}) = {:smtp => { :host => 'localhost', :port => '25', :domain => 'localhost.localdomain' }} o = [:smtp].merge([:smtp]) smtp = Net::SMTP.new(o[:host], o[:port]) if o.include?(:auth) smtp.enable_starttls smtp.start(o[:domain], o[:user], o[:password], o[:auth]) else smtp.start(o[:domain]) end smtp. tmail.to_s, tmail.from, tmail.to smtp.finish end |
.via_options ⇒ Object
50 51 52 |
# File 'lib/pony.rb', line 50 def self. %w(sendmail smtp) end |