flowers-pony 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/pony.rb +75 -0
  2. metadata +54 -0
@@ -0,0 +1,75 @@
1
+ require 'rubygems'
2
+ require 'net/smtp'
3
+ begin
4
+ require 'tmail'
5
+ rescue LoadError
6
+ require 'actionmailer'
7
+ end
8
+
9
+ module Pony
10
+ def self.mail(options)
11
+ raise(ArgumentError, ":to is required") unless options[:to]
12
+
13
+ via = options.delete(:via)
14
+ if via.nil?
15
+ transport build_tmail(options)
16
+ else
17
+ if via_options.include?(via.to_s)
18
+ send("transport_via_#{via}", build_tmail(options), options)
19
+ else
20
+ raise(ArgumentError, ":via must be either smtp or sendmail")
21
+ end
22
+ end
23
+ end
24
+
25
+ def self.build_tmail(options)
26
+ mail = TMail::Mail.new
27
+ mail.to = options[:to]
28
+ mail.from = options[:from] || 'pony@unknown'
29
+ mail.subject = options[:subject]
30
+ mail.body = options[:body] || ""
31
+ if options[:html_body] == true
32
+ mail.set_content_type('text','html')
33
+ end
34
+ mail
35
+ end
36
+
37
+ def self.sendmail_binary
38
+ @sendmail_binary ||= `which sendmail`.chomp
39
+ end
40
+
41
+ def self.transport(tmail)
42
+ if File.executable? sendmail_binary
43
+ transport_via_sendmail(tmail)
44
+ else
45
+ transport_via_smtp(tmail)
46
+ end
47
+ end
48
+
49
+ def self.via_options
50
+ %w(sendmail smtp)
51
+ end
52
+
53
+ def self.transport_via_sendmail(tmail, options={})
54
+ IO.popen('-', 'w+') do |pipe|
55
+ if pipe
56
+ pipe.write(tmail.to_s)
57
+ else
58
+ exec(sendmail_binary, *tmail.to)
59
+ end
60
+ end
61
+ end
62
+
63
+ def self.transport_via_smtp(tmail, options={:smtp => {}})
64
+ default_options = {:smtp => { :host => 'localhost', :port => '25', :domain => 'localhost.localdomain' }}
65
+ o = default_options[:smtp].merge(options[:smtp])
66
+ smtp = Net::SMTP.new(o[:host], o[:port])
67
+ if o.include?(:auth)
68
+ smtp.start(o[:domain], o[:user], o[:password], o[:auth])
69
+ else
70
+ smtp.start(o[:domain])
71
+ end
72
+ smtp.send_message tmail.to_s, tmail.from, tmail.to
73
+ smtp.finish
74
+ end
75
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: flowers-pony
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.2
5
+ platform: ruby
6
+ authors:
7
+ - Adam Wiggings
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-06-08 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: The express way to send mail from Ruby.
17
+ email: edu@flowersinspace.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - lib/pony.rb
26
+ has_rdoc: true
27
+ homepage: http://github.com/flowers/pony
28
+ post_install_message:
29
+ rdoc_options:
30
+ - --inline-source
31
+ - --charset=UTF-8
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: "0"
39
+ version:
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: "0"
45
+ version:
46
+ requirements: []
47
+
48
+ rubyforge_project: lib
49
+ rubygems_version: 1.2.0
50
+ signing_key:
51
+ specification_version: 2
52
+ summary: The express way to send mail from Ruby.
53
+ test_files: []
54
+