pony 1.1 → 1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +5 -0
- data/lib/pony.rb +115 -119
- data/pony.gemspec +17 -16
- data/spec/pony_spec.rb +223 -229
- metadata +18 -5
- data/lib/pony.rb~ +0 -110
- data/spec/pony_spec.rb~ +0 -232
data/README.rdoc
CHANGED
@@ -123,6 +123,7 @@ Rick Olson
|
|
123
123
|
Stephen Celis,
|
124
124
|
Thomas Hurst,
|
125
125
|
Kalin Harvey
|
126
|
+
Carl Hörberg
|
126
127
|
|
127
128
|
Released under the MIT License: http://www.opensource.org/licenses/mit-license.php
|
128
129
|
|
@@ -132,6 +133,10 @@ mailing list: ponyrb@googlegroups.com
|
|
132
133
|
|
133
134
|
== Releases
|
134
135
|
|
136
|
+
1.2
|
137
|
+
* Remove limitations on :via, and let mail handle it (this means you can say things like :via => test)
|
138
|
+
* Add reply-to option and a bundler file
|
139
|
+
|
135
140
|
1.1
|
136
141
|
* Add default options
|
137
142
|
|
data/lib/pony.rb
CHANGED
@@ -102,138 +102,134 @@ require 'base64'
|
|
102
102
|
|
103
103
|
module Pony
|
104
104
|
|
105
|
-
|
105
|
+
@@options = {}
|
106
106
|
|
107
107
|
# Default options can be set so that they don't have to be repeated.
|
108
108
|
#
|
109
109
|
# Pony.options = { :from => 'noreply@example.com', :via => :smtp, :via_options => { :host => 'smtp.yourserver.com' } }
|
110
110
|
# Pony.mail(:to => 'foo@bar') # Sends mail to foo@bar from noreply@example.com using smtp
|
111
111
|
# Pony.mail(:from => 'pony@example.com', :to => 'foo@bar') # Sends mail to foo@bar from pony@example.com using smtp
|
112
|
-
|
113
|
-
|
114
|
-
|
112
|
+
def self.options=(value)
|
113
|
+
@@options = value
|
114
|
+
end
|
115
115
|
|
116
|
-
|
117
|
-
|
118
|
-
|
116
|
+
def self.options()
|
117
|
+
@@options
|
118
|
+
end
|
119
119
|
|
120
120
|
# Send an email
|
121
121
|
# Pony.mail(:to => 'you@example.com', :from => 'me@example.com', :subject => 'hi', :body => 'Hello there.')
|
122
122
|
# Pony.mail(:to => 'you@example.com', :html_body => '<h1>Hello there!</h1>', :body => "In case you can't read html, Hello there.")
|
123
123
|
# Pony.mail(:to => 'you@example.com', :cc => 'him@example.com', :from => 'me@example.com', :subject => 'hi', :body => 'Howsit!')
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
124
|
+
def self.mail(options)
|
125
|
+
options = @@options.merge options
|
126
|
+
raise(ArgumentError, ":to is required") unless options[:to]
|
127
|
+
|
128
|
+
options[:via] = default_delivery_method unless options.has_key?(:via)
|
129
|
+
|
130
|
+
options = cross_reference_depricated_fields(options)
|
131
|
+
|
132
|
+
if options.has_key?(:via) && options[:via] == :sendmail
|
133
|
+
options[:via_options] ||= {}
|
134
|
+
options[:via_options][:location] ||= sendmail_binary
|
135
|
+
end
|
136
|
+
|
137
|
+
deliver build_mail(options)
|
138
|
+
end
|
139
|
+
|
140
|
+
private
|
141
|
+
|
142
|
+
def self.cross_reference_depricated_fields(options)
|
143
|
+
if options.has_key?(:smtp)
|
144
|
+
warn depricated_message(:smtp, :via_options)
|
145
|
+
options[:via_options] = options.delete(:smtp)
|
146
|
+
end
|
147
|
+
|
148
|
+
# cross-reference pony options to be compatible with keys mail expects
|
149
|
+
{ :host => :address, :user => :user_name, :auth => :authentication, :tls => :enable_starttls_auto }.each do |key, val|
|
150
|
+
if options[:via_options] && options[:via_options].has_key?(key)
|
151
|
+
warn depricated_message(key, val)
|
152
|
+
options[:via_options][val] = options[:via_options].delete(key)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
if options[:content_type] && options[:content_type] =~ /html/ && !options[:html_body]
|
157
|
+
warn depricated_message(:content_type, :html_body)
|
158
|
+
options[:html_body] = options[:body]
|
159
|
+
end
|
160
|
+
|
161
|
+
return options
|
162
|
+
end
|
163
|
+
|
164
|
+
def self.deliver(mail)
|
165
|
+
mail.deliver!
|
166
|
+
end
|
167
|
+
|
168
|
+
def self.default_delivery_method
|
169
|
+
File.executable?(sendmail_binary) ? :sendmail : :smtp
|
170
|
+
end
|
171
|
+
|
172
|
+
def self.build_mail(options)
|
173
|
+
mail = Mail.new do
|
174
|
+
to options[:to]
|
175
|
+
from options[:from] || 'pony@unknown'
|
176
|
+
cc options[:cc]
|
177
|
+
reply_to options[:reply_to]
|
178
|
+
bcc options[:bcc]
|
179
|
+
subject options[:subject]
|
180
|
+
date options[:date] || Time.now
|
181
|
+
message_id options[:message_id]
|
182
|
+
sender options[:sender] if options[:sender]
|
183
|
+
|
184
|
+
if options[:html_body]
|
185
|
+
html_part do
|
186
|
+
content_type 'text/html; charset=UTF-8'
|
187
|
+
body options[:html_body]
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
# If we're using attachments, the body needs to be a separate part. If not,
|
192
192
|
# we can just set the body directly.
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
193
|
+
if options[:body] && (options[:html_body] || options[:attachments])
|
194
|
+
text_part do
|
195
|
+
body options[:body]
|
196
|
+
end
|
197
|
+
elsif options[:body]
|
198
|
+
body options[:body]
|
199
|
+
end
|
200
|
+
|
201
|
+
delivery_method options[:via], (options.has_key?(:via_options) ? options[:via_options] : {})
|
202
202
|
end
|
203
203
|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
warning_message = "warning: '#{method}' is deprecated"
|
236
|
-
warning_message += "; use '#{alternative}' instead." if alternative
|
237
|
-
return warning_message
|
238
|
-
end
|
204
|
+
(options[:attachments] || []).each do |name, body|
|
205
|
+
# mime-types wants to send these as "quoted-printable"
|
206
|
+
if name =~ /\.xlsx$/
|
207
|
+
mail.attachments[name] = {
|
208
|
+
:content => Base64.encode64(body),
|
209
|
+
:transfer_encoding => :base64
|
210
|
+
}
|
211
|
+
else
|
212
|
+
mail.attachments[name] = body
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
(options[:headers] ||= {}).each do |key, value|
|
217
|
+
mail[key] = value
|
218
|
+
end
|
219
|
+
|
220
|
+
mail.charset = options[:charset] if options[:charset] # charset must be set after setting content_type
|
221
|
+
|
222
|
+
mail
|
223
|
+
end
|
224
|
+
|
225
|
+
def self.sendmail_binary
|
226
|
+
sendmail = `which sendmail`.chomp
|
227
|
+
sendmail.empty? ? '/usr/sbin/sendmail' : sendmail
|
228
|
+
end
|
229
|
+
|
230
|
+
def self.depricated_message(method, alternative)
|
231
|
+
warning_message = "warning: '#{method}' is deprecated"
|
232
|
+
warning_message += "; use '#{alternative}' instead." if alternative
|
233
|
+
return warning_message
|
234
|
+
end
|
239
235
|
end
|
data/pony.gemspec
CHANGED
@@ -1,22 +1,23 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
|
-
|
5
|
-
|
4
|
+
s.name = %q{pony}
|
5
|
+
s.version = "1.2"
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
s.description = "Send email in one command: Pony.mail(:to => 'someone@example.com', :body => 'hello')"
|
8
|
+
s.summary = s.description
|
9
|
+
s.authors = ["Adam Wiggins", "maint: Ben Prew"]
|
10
|
+
s.email = %q{ben.prew@gmail.com}
|
11
|
+
s.homepage = %q{http://github.com/benprew/pony}
|
12
|
+
s.rubyforge_project = "pony"
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
14
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
15
|
+
s.files = ["README.rdoc", "Rakefile", "pony.gemspec" ] + Dir.glob("{lib,spec}/**/*")
|
16
|
+
s.has_rdoc = false
|
17
|
+
s.rdoc_options = ["--inline-source", "--charset=UTF-8"]
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
s.rubygems_version = %q{1.3.1}
|
20
|
+
s.add_dependency 'mail', '>2.0'
|
21
|
+
s.add_development_dependency "rspec", ">= 2.0.0"
|
22
|
+
s.platform = Gem::Platform::RUBY
|
22
23
|
end
|
data/spec/pony_spec.rb
CHANGED
@@ -3,234 +3,228 @@ require File.dirname(__FILE__) + '/base'
|
|
3
3
|
|
4
4
|
describe Pony do
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
input = { :from => 'noreply@pony' }
|
230
|
-
Pony.options = input
|
231
|
-
output = Pony.options
|
232
|
-
output.should == input
|
233
|
-
end
|
234
|
-
end
|
6
|
+
before(:each) do
|
7
|
+
Pony.stub!(:deliver)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "sends mail" do
|
11
|
+
Pony.should_receive(:deliver) do |mail|
|
12
|
+
mail.to.should == [ 'joe@example.com' ]
|
13
|
+
mail.from.should == [ 'sender@example.com' ]
|
14
|
+
mail.subject.should == 'hi'
|
15
|
+
mail.body.should == 'Hello, Joe.'
|
16
|
+
end
|
17
|
+
Pony.mail(:to => 'joe@example.com', :from => 'sender@example.com', :subject => 'hi', :body => 'Hello, Joe.')
|
18
|
+
end
|
19
|
+
|
20
|
+
it "requires :to param" do
|
21
|
+
lambda { Pony.mail({}) }.should raise_error(ArgumentError)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "doesn't require any other param" do
|
25
|
+
lambda { Pony.mail(:to => 'joe@example.com') }.should_not raise_error
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should handle depricated options gracefully" do
|
29
|
+
Pony.should_receive(:build_mail).with(hash_including(:via_options => {:address => 'test'}))
|
30
|
+
Pony.mail(:to => 'foo@bar', :smtp => { :host => 'test' }, :via => :smtp)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should handle depricated content-type gracefully" do
|
34
|
+
Pony.should_receive(:build_mail).with(hash_including(:html_body => "this is <h1>HTML</h1>"))
|
35
|
+
Pony.mail(:to => 'foo@bar', :content_type => 'text/html', :body => 'this is <h1>HTML</h1>')
|
36
|
+
end
|
37
|
+
####################
|
38
|
+
|
39
|
+
describe "builds a Mail object with field:" do
|
40
|
+
it "to" do
|
41
|
+
Pony.build_mail(:to => 'joe@example.com').to.should == [ 'joe@example.com' ]
|
42
|
+
end
|
43
|
+
|
44
|
+
it "to with multiple recipients" do
|
45
|
+
Pony.build_mail(:to => 'joe@example.com, friedrich@example.com').to.should == [ 'joe@example.com', 'friedrich@example.com' ]
|
46
|
+
end
|
47
|
+
|
48
|
+
it "to with multiple recipients and names" do
|
49
|
+
Pony.build_mail(:to => 'joe@example.com, "Friedrich Hayek" <friedrich@example.com>').to.should == [ 'joe@example.com', 'friedrich@example.com' ]
|
50
|
+
end
|
51
|
+
|
52
|
+
it "to with multiple recipients and names in an array" do
|
53
|
+
Pony.build_mail(:to => ['joe@example.com', '"Friedrich Hayek" <friedrich@example.com>']).to.should == [ 'joe@example.com', 'friedrich@example.com' ]
|
54
|
+
end
|
55
|
+
|
56
|
+
it "cc" do
|
57
|
+
Pony.build_mail(:cc => 'joe@example.com').cc.should == [ 'joe@example.com' ]
|
58
|
+
end
|
59
|
+
|
60
|
+
it "reply_to" do
|
61
|
+
Pony.build_mail(:reply_to => 'joe@example.com').reply_to.should == [ 'joe@example.com' ]
|
62
|
+
end
|
63
|
+
|
64
|
+
it "cc with multiple recipients" do
|
65
|
+
Pony.build_mail(:cc => 'joe@example.com, friedrich@example.com').cc.should == [ 'joe@example.com', 'friedrich@example.com' ]
|
66
|
+
end
|
67
|
+
|
68
|
+
it "from" do
|
69
|
+
Pony.build_mail(:from => 'joe@example.com').from.should == [ 'joe@example.com' ]
|
70
|
+
end
|
71
|
+
|
72
|
+
it "bcc" do
|
73
|
+
Pony.build_mail(:bcc => 'joe@example.com').bcc.should == [ 'joe@example.com' ]
|
74
|
+
end
|
75
|
+
|
76
|
+
it "bcc with multiple recipients" do
|
77
|
+
Pony.build_mail(:bcc => 'joe@example.com, friedrich@example.com').bcc.should == [ 'joe@example.com', 'friedrich@example.com' ]
|
78
|
+
end
|
79
|
+
|
80
|
+
it "charset" do
|
81
|
+
mail = Pony.build_mail(:charset => 'UTF-8')
|
82
|
+
mail.charset.should == 'UTF-8'
|
83
|
+
end
|
84
|
+
|
85
|
+
it "default charset" do
|
86
|
+
Pony.build_mail(:body => 'body').charset.should == 'UTF-8'
|
87
|
+
Pony.build_mail(:body => 'body', :content_type => 'text/html').charset.should == 'UTF-8'
|
88
|
+
end
|
89
|
+
|
90
|
+
it "from (default)" do
|
91
|
+
Pony.build_mail({}).from.should == [ 'pony@unknown' ]
|
92
|
+
end
|
93
|
+
|
94
|
+
it "subject" do
|
95
|
+
Pony.build_mail(:subject => 'hello').subject.should == 'hello'
|
96
|
+
end
|
97
|
+
|
98
|
+
it "body" do
|
99
|
+
Pony.build_mail(:body => 'What do you know, Joe?').body.should == 'What do you know, Joe?'
|
100
|
+
end
|
101
|
+
|
102
|
+
it "html_body" do
|
103
|
+
Pony.build_mail(:html_body => 'What do you know, Joe?').parts.first.body.should == 'What do you know, Joe?'
|
104
|
+
Pony.build_mail(:html_body => 'What do you know, Joe?').parts.first.content_type.should == 'text/html; charset=UTF-8'
|
105
|
+
end
|
106
|
+
|
107
|
+
it "date" do
|
108
|
+
now = Time.now
|
109
|
+
Pony.build_mail(:date => now).date.should == DateTime.parse(now.to_s)
|
110
|
+
end
|
111
|
+
|
112
|
+
it "content_type of html should set html_body" do
|
113
|
+
Pony.should_receive(:build_mail).with(hash_including(:html_body => '<h1>test</h1>'))
|
114
|
+
Pony.mail(:to => 'foo@bar', :content_type => 'text/html', :body => '<h1>test</h1>')
|
115
|
+
end
|
116
|
+
|
117
|
+
it "message_id" do
|
118
|
+
Pony.build_mail(:message_id => '<abc@def.com>').message_id.should == 'abc@def.com'
|
119
|
+
end
|
120
|
+
|
121
|
+
it "custom headers" do
|
122
|
+
Pony.build_mail(:headers => {"List-ID" => "<abc@def.com>"})['List-ID'].to_s.should == '<abc@def.com>'
|
123
|
+
end
|
124
|
+
|
125
|
+
it "sender" do
|
126
|
+
Pony.build_mail(:sender => "abc@def.com")['Sender'].to_s.should == 'abc@def.com'
|
127
|
+
end
|
128
|
+
|
129
|
+
it "utf-8 encoded subject line" do
|
130
|
+
mail = Pony.build_mail(:to => 'btp@foo', :subject => 'Café', :body => 'body body body')
|
131
|
+
mail['subject'].encoded.should =~ /^Subject: =\?UTF-8/;
|
132
|
+
end
|
133
|
+
|
134
|
+
it "attachments" do
|
135
|
+
mail = Pony.build_mail(:attachments => {"foo.txt" => "content of foo.txt"}, :body => 'test')
|
136
|
+
mail.parts.length.should == 2
|
137
|
+
mail.parts.first.to_s.should =~ /Content-Type: text\/plain/
|
138
|
+
end
|
139
|
+
|
140
|
+
it "suggests mime-type" do
|
141
|
+
mail = Pony.build_mail(:attachments => {"foo.pdf" => "content of foo.pdf"})
|
142
|
+
mail.parts.length.should == 1
|
143
|
+
mail.parts.first.to_s.should =~ /Content-Type: application\/pdf/
|
144
|
+
mail.parts.first.to_s.should =~ /filename=foo.pdf/
|
145
|
+
mail.parts.first.content_transfer_encoding.to_s.should == 'base64'
|
146
|
+
end
|
147
|
+
|
148
|
+
it "encodes xlsx files as base64" do
|
149
|
+
mail = Pony.build_mail(:attachments => {"foo.xlsx" => "content of foo.xlsx"})
|
150
|
+
mail.parts.length.should == 1
|
151
|
+
mail.parts.first.to_s.should =~ /Content-Type: application\/vnd.openxmlformats-officedocument.spreadsheetml.sheet/
|
152
|
+
mail.parts.first.to_s.should =~ /filename=foo.xlsx/
|
153
|
+
mail.parts.first.content_transfer_encoding.to_s.should == 'base64'
|
154
|
+
end
|
155
|
+
|
156
|
+
it "passes cc and bcc as the list of recipients" do
|
157
|
+
mail = Pony.build_mail(:to => ['to'], :cc => ['cc'], :from => ['from'], :bcc => ['bcc'])
|
158
|
+
mail.destinations.should == ['to', 'cc', 'bcc']
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
describe "transport" do
|
163
|
+
it "transports via smtp if no sendmail binary" do
|
164
|
+
Pony.stub!(:sendmail_binary).and_return('/does/not/exist')
|
165
|
+
Pony.should_receive(:build_mail).with(hash_including(:via => :smtp))
|
166
|
+
Pony.mail(:to => 'foo@bar')
|
167
|
+
end
|
168
|
+
|
169
|
+
it "defaults to sendmail if no via is specified and sendmail exists" do
|
170
|
+
File.stub!(:executable?).and_return(true)
|
171
|
+
Pony.should_receive(:build_mail).with(hash_including(:via => :sendmail))
|
172
|
+
Pony.mail(:to => 'foo@bar')
|
173
|
+
end
|
174
|
+
|
175
|
+
describe "SMTP transport" do
|
176
|
+
|
177
|
+
it "defaults to localhost as the SMTP server" do
|
178
|
+
mail = Pony.build_mail(:to => "foo@bar", :enable_starttls_auto => true, :via => :smtp)
|
179
|
+
mail.delivery_method.settings[:address].should == 'localhost'
|
180
|
+
end
|
181
|
+
|
182
|
+
it "enable starttls when tls option is true" do
|
183
|
+
mail = Pony.build_mail(:to => "foo@bar", :enable_starttls_auto => true, :via => :smtp)
|
184
|
+
mail.delivery_method.settings[:enable_starttls_auto].should == true
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
describe ":via option should over-ride the default transport mechanism" do
|
190
|
+
it "should send via sendmail if :via => sendmail" do
|
191
|
+
mail = Pony.build_mail(:to => 'joe@example.com', :via => :sendmail)
|
192
|
+
mail.delivery_method.kind_of?(Mail::Sendmail).should == true
|
193
|
+
end
|
194
|
+
|
195
|
+
it "should send via smtp if :via => smtp" do
|
196
|
+
mail = Pony.build_mail(:to => 'joe@example.com', :via => :smtp)
|
197
|
+
mail.delivery_method.kind_of?(Mail::SMTP).should == true
|
198
|
+
end
|
199
|
+
|
200
|
+
end
|
201
|
+
|
202
|
+
describe "sendmail binary location" do
|
203
|
+
it "should default to /usr/sbin/sendmail if not in path" do
|
204
|
+
Pony.stub!(:'`').and_return('')
|
205
|
+
Pony.sendmail_binary.should == '/usr/sbin/sendmail'
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
describe "default options" do
|
210
|
+
it "should use default options" do
|
211
|
+
Pony.should_receive(:build_mail).with(hash_including(:from => 'noreply@pony'))
|
212
|
+
Pony.options = { :from => 'noreply@pony' }
|
213
|
+
Pony.mail(:to => 'foo@bar')
|
214
|
+
end
|
215
|
+
|
216
|
+
it "should merge default options with options" do
|
217
|
+
Pony.should_receive(:build_mail).with(hash_including(:from => 'override@pony'))
|
218
|
+
Pony.options = { :from => 'noreply@pony' }
|
219
|
+
Pony.mail(:from => 'override@pony', :to => "foo@bar")
|
220
|
+
end
|
221
|
+
|
222
|
+
it "should return the default options" do
|
223
|
+
input = { :from => 'noreply@pony' }
|
224
|
+
Pony.options = input
|
225
|
+
output = Pony.options
|
226
|
+
output.should == input
|
227
|
+
end
|
228
|
+
end
|
235
229
|
|
236
230
|
end
|
metadata
CHANGED
@@ -4,8 +4,8 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 1
|
7
|
-
-
|
8
|
-
version: "1.
|
7
|
+
- 2
|
8
|
+
version: "1.2"
|
9
9
|
platform: ruby
|
10
10
|
authors:
|
11
11
|
- Adam Wiggins
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date:
|
17
|
+
date: 2011-04-20 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -31,6 +31,21 @@ dependencies:
|
|
31
31
|
version: "2.0"
|
32
32
|
type: :runtime
|
33
33
|
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: rspec
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 2
|
44
|
+
- 0
|
45
|
+
- 0
|
46
|
+
version: 2.0.0
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id002
|
34
49
|
description: "Send email in one command: Pony.mail(:to => 'someone@example.com', :body => 'hello')"
|
35
50
|
email: ben.prew@gmail.com
|
36
51
|
executables: []
|
@@ -43,9 +58,7 @@ files:
|
|
43
58
|
- README.rdoc
|
44
59
|
- Rakefile
|
45
60
|
- pony.gemspec
|
46
|
-
- lib/pony.rb~
|
47
61
|
- lib/pony.rb
|
48
|
-
- spec/pony_spec.rb~
|
49
62
|
- spec/base.rb
|
50
63
|
- spec/pony_spec.rb
|
51
64
|
has_rdoc: true
|
data/lib/pony.rb~
DELETED
@@ -1,110 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'net/smtp'
|
3
|
-
require 'mime/types'
|
4
|
-
begin
|
5
|
-
require 'smtp_tls'
|
6
|
-
rescue LoadError
|
7
|
-
end
|
8
|
-
require 'base64'
|
9
|
-
begin
|
10
|
-
require 'tmail'
|
11
|
-
rescue LoadError
|
12
|
-
require 'actionmailer'
|
13
|
-
end
|
14
|
-
|
15
|
-
module Pony
|
16
|
-
def self.mail(options)
|
17
|
-
raise(ArgumentError, ":to is required") unless options[:to]
|
18
|
-
|
19
|
-
via = options.delete(:via)
|
20
|
-
if via.nil?
|
21
|
-
transport build_tmail(options)
|
22
|
-
else
|
23
|
-
if via_options.include?(via.to_s)
|
24
|
-
send("transport_via_#{via}", build_tmail(options), options)
|
25
|
-
else
|
26
|
-
raise(ArgumentError, ":via must be either smtp or sendmail")
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.build_tmail(options)
|
32
|
-
mail = TMail::Mail.new
|
33
|
-
mail.to = options[:to]
|
34
|
-
mail.cc = options[:cc]
|
35
|
-
mail.bcc = options[:bcc]
|
36
|
-
mail.from = options[:from] || 'pony@unknown'
|
37
|
-
mail.subject = options[:subject]
|
38
|
-
mail.date = options[:date] || Time.now
|
39
|
-
mail.message_id = options[:message_id]
|
40
|
-
if options[:attachments]
|
41
|
-
# If message has attachment, then body must be sent as a message part
|
42
|
-
# or it will not be interpreted correctly by client.
|
43
|
-
body = TMail::Mail.new
|
44
|
-
body.body = options[:body] || ""
|
45
|
-
body.content_type = options[:content_type] || "text/plain"
|
46
|
-
mail.parts.push body
|
47
|
-
(options[:attachments] || []).each do |name, body|
|
48
|
-
attachment = TMail::Mail.new
|
49
|
-
attachment.transfer_encoding = "base64"
|
50
|
-
attachment.body = Base64.encode64(body)
|
51
|
-
content_type = MIME::Types.type_for(name).to_s
|
52
|
-
attachment.content_type = content_type unless content_type == ""
|
53
|
-
attachment.set_content_disposition "attachment", "filename" => name
|
54
|
-
mail.parts.push attachment
|
55
|
-
end
|
56
|
-
else
|
57
|
-
mail.content_type = options[:content_type] || "text/plain"
|
58
|
-
mail.body = options[:body] || ""
|
59
|
-
end
|
60
|
-
(options[:headers] ||= {}).each do |key, value|
|
61
|
-
mail[key] = value
|
62
|
-
end
|
63
|
-
mail.charset = options[:charset] # charset must be set after setting content_type
|
64
|
-
mail
|
65
|
-
end
|
66
|
-
|
67
|
-
def self.sendmail_binary
|
68
|
-
sendmail = `which sendmail`.chomp
|
69
|
-
sendmail.empty? ? '/usr/sbin/sendmail' : sendmail
|
70
|
-
end
|
71
|
-
|
72
|
-
def self.transport(tmail)
|
73
|
-
if File.executable? sendmail_binary
|
74
|
-
transport_via_sendmail(tmail)
|
75
|
-
else
|
76
|
-
transport_via_smtp(tmail)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def self.via_options
|
81
|
-
%w(sendmail smtp)
|
82
|
-
end
|
83
|
-
|
84
|
-
def self.transport_via_sendmail(tmail, options={})
|
85
|
-
IO.popen('-', 'w+') do |pipe|
|
86
|
-
if pipe
|
87
|
-
pipe.write(tmail.to_s)
|
88
|
-
else
|
89
|
-
exec(sendmail_binary, "-t")
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
def self.transport_via_smtp(tmail, options={:smtp => {}})
|
95
|
-
default_options = {:smtp => { :host => 'localhost', :port => '25', :domain => 'localhost.localdomain' }}
|
96
|
-
o = default_options[:smtp].merge(options[:smtp])
|
97
|
-
smtp = Net::SMTP.new(o[:host], o[:port])
|
98
|
-
if o[:tls]
|
99
|
-
raise "You may need: gem install smtp_tls" unless smtp.respond_to?(:enable_starttls)
|
100
|
-
smtp.enable_starttls
|
101
|
-
end
|
102
|
-
if o.include?(:auth)
|
103
|
-
smtp.start(o[:domain], o[:user], o[:password], o[:auth])
|
104
|
-
else
|
105
|
-
smtp.start(o[:domain])
|
106
|
-
end
|
107
|
-
smtp.send_message tmail.to_s, tmail.from, tmail.destinations
|
108
|
-
smtp.finish
|
109
|
-
end
|
110
|
-
end
|
data/spec/pony_spec.rb~
DELETED
@@ -1,232 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/base'
|
2
|
-
|
3
|
-
describe Pony do
|
4
|
-
it "sends mail" do
|
5
|
-
Pony.should_receive(:transport) do |tmail|
|
6
|
-
tmail.to.should == [ 'joe@example.com' ]
|
7
|
-
tmail.from.should == [ 'sender@example.com' ]
|
8
|
-
tmail.subject.should == 'hi'
|
9
|
-
tmail.body.should == 'Hello, Joe.'
|
10
|
-
end
|
11
|
-
Pony.mail(:to => 'joe@example.com', :from => 'sender@example.com', :subject => 'hi', :body => 'Hello, Joe.')
|
12
|
-
end
|
13
|
-
|
14
|
-
it "requires :to param" do
|
15
|
-
Pony.stub!(:transport)
|
16
|
-
lambda { Pony.mail({}) }.should raise_error(ArgumentError)
|
17
|
-
end
|
18
|
-
|
19
|
-
it "doesn't require any other param" do
|
20
|
-
Pony.stub!(:transport)
|
21
|
-
lambda { Pony.mail(:to => 'joe@example.com') }.should_not raise_error
|
22
|
-
end
|
23
|
-
|
24
|
-
####################
|
25
|
-
|
26
|
-
describe "builds a TMail object with field:" do
|
27
|
-
it "to" do
|
28
|
-
Pony.build_tmail(:to => 'joe@example.com').to.should == [ 'joe@example.com' ]
|
29
|
-
end
|
30
|
-
|
31
|
-
it "to with multiple recipients" do
|
32
|
-
Pony.build_tmail(:to => 'joe@example.com, friedrich@example.com').to.should == [ 'joe@example.com', 'friedrich@example.com' ]
|
33
|
-
end
|
34
|
-
|
35
|
-
it "to with multiple recipients and names" do
|
36
|
-
Pony.build_tmail(:to => 'joe@example.com, "Friedrich Hayek" <friedrich@example.com>').to.should == [ 'joe@example.com', 'friedrich@example.com' ]
|
37
|
-
end
|
38
|
-
|
39
|
-
it "to with multiple recipients and names in an array" do
|
40
|
-
Pony.build_tmail(:to => ['joe@example.com', '"Friedrich Hayek" <friedrich@example.com>']).to.should == [ 'joe@example.com', 'friedrich@example.com' ]
|
41
|
-
end
|
42
|
-
|
43
|
-
it "cc" do
|
44
|
-
Pony.build_tmail(:cc => 'joe@example.com').cc.should == [ 'joe@example.com' ]
|
45
|
-
end
|
46
|
-
|
47
|
-
it "cc with multiple recipients" do
|
48
|
-
Pony.build_tmail(:cc => 'joe@example.com, friedrich@example.com').cc.should == [ 'joe@example.com', 'friedrich@example.com' ]
|
49
|
-
end
|
50
|
-
|
51
|
-
it "from" do
|
52
|
-
Pony.build_tmail(:from => 'joe@example.com').from.should == [ 'joe@example.com' ]
|
53
|
-
end
|
54
|
-
|
55
|
-
it "bcc" do
|
56
|
-
Pony.build_tmail(:bcc => 'joe@example.com').bcc.should == [ 'joe@example.com' ]
|
57
|
-
end
|
58
|
-
|
59
|
-
it "bcc with multiple recipients" do
|
60
|
-
Pony.build_tmail(:bcc => 'joe@example.com, friedrich@example.com').bcc.should == [ 'joe@example.com', 'friedrich@example.com' ]
|
61
|
-
end
|
62
|
-
|
63
|
-
it "charset" do
|
64
|
-
Pony.build_tmail(:charset => 'UTF-8').charset.should == 'UTF-8'
|
65
|
-
end
|
66
|
-
|
67
|
-
it "default charset" do
|
68
|
-
Pony.build_tmail(:body => 'body').charset.should == nil
|
69
|
-
Pony.build_tmail(:body => 'body', :content_type => 'text/html').charset.should == nil
|
70
|
-
end
|
71
|
-
|
72
|
-
it "from (default)" do
|
73
|
-
Pony.build_tmail({}).from.should == [ 'pony@unknown' ]
|
74
|
-
end
|
75
|
-
|
76
|
-
it "subject" do
|
77
|
-
Pony.build_tmail(:subject => 'hello').subject.should == 'hello'
|
78
|
-
end
|
79
|
-
|
80
|
-
it "body" do
|
81
|
-
Pony.build_tmail(:body => 'What do you know, Joe?').body.should == 'What do you know, Joe?'
|
82
|
-
end
|
83
|
-
|
84
|
-
it "content_type" do
|
85
|
-
Pony.build_tmail(:content_type => 'text/html').content_type.should == 'text/html'
|
86
|
-
end
|
87
|
-
|
88
|
-
it "message_id" do
|
89
|
-
Pony.build_tmail(:message_id => '<abc@def.com>').message_id.should == '<abc@def.com>'
|
90
|
-
end
|
91
|
-
|
92
|
-
it "custom headers" do
|
93
|
-
Pony.build_tmail(:headers => {"List-ID" => "<abc@def.com>"})['List-ID'].to_s.should == '<abc@def.com>'
|
94
|
-
end
|
95
|
-
|
96
|
-
it "attachments" do
|
97
|
-
tmail = Pony.build_tmail(:attachments => {"foo.txt" => "content of foo.txt"})
|
98
|
-
tmail.should have(2).parts
|
99
|
-
tmail.parts.first.to_s.should == "Content-Type: text/plain\n\n"
|
100
|
-
tmail.parts.last.to_s.should == <<-PART
|
101
|
-
Content-Type: text/plain
|
102
|
-
Content-Transfer-Encoding: Base64
|
103
|
-
Content-Disposition: attachment; filename=foo.txt
|
104
|
-
|
105
|
-
Y29udGVudCBvZiBmb28udHh0
|
106
|
-
PART
|
107
|
-
end
|
108
|
-
|
109
|
-
it "suggests mime-type" do
|
110
|
-
tmail = Pony.build_tmail(:attachments => {"foo.pdf" => "content of foo.pdf"})
|
111
|
-
tmail.should have(2).parts
|
112
|
-
tmail.parts.first.to_s.should == "Content-Type: text/plain\n\n"
|
113
|
-
tmail.parts.last.to_s.should == <<-PART
|
114
|
-
Content-Type: application/pdf
|
115
|
-
Content-Transfer-Encoding: Base64
|
116
|
-
Content-Disposition: attachment; filename=foo.pdf
|
117
|
-
|
118
|
-
Y29udGVudCBvZiBmb28ucGRm
|
119
|
-
PART
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
describe "transport" do
|
124
|
-
it "transports via the sendmail binary if it exists" do
|
125
|
-
File.stub!(:executable?).and_return(true)
|
126
|
-
Pony.should_receive(:transport_via_sendmail).with(:tmail)
|
127
|
-
Pony.transport(:tmail)
|
128
|
-
end
|
129
|
-
|
130
|
-
it "transports via smtp if no sendmail binary" do
|
131
|
-
Pony.stub!(:sendmail_binary).and_return('/does/not/exist')
|
132
|
-
Pony.should_receive(:transport_via_smtp).with(:tmail)
|
133
|
-
Pony.transport(:tmail)
|
134
|
-
end
|
135
|
-
|
136
|
-
it "transports mail via /usr/sbin/sendmail binary" do
|
137
|
-
pipe = mock('sendmail pipe')
|
138
|
-
IO.should_receive(:popen).with('-',"w+").and_yield(pipe)
|
139
|
-
pipe.should_receive(:write).with('message')
|
140
|
-
Pony.transport_via_sendmail(mock('tmail', :to => ['to'], :from => ['from'], :to_s => 'message'))
|
141
|
-
end
|
142
|
-
|
143
|
-
describe "SMTP transport" do
|
144
|
-
before do
|
145
|
-
@smtp = mock('net::smtp object')
|
146
|
-
@smtp.stub!(:start)
|
147
|
-
@smtp.stub!(:send_message)
|
148
|
-
@smtp.stub!(:finish)
|
149
|
-
Net::SMTP.stub!(:new).and_return(@smtp)
|
150
|
-
end
|
151
|
-
|
152
|
-
it "passes cc and bcc as the list of recipients" do
|
153
|
-
@smtp.should_receive(:send_message).with("message", ['from'], ['to', 'cc', 'bcc'])
|
154
|
-
Pony.transport_via_smtp(mock('tmail', :to => ['to'], :cc => ['cc'], :from => ['from'], :to_s => 'message', :bcc => ['bcc'], :destinations => ['to', 'cc', 'bcc']))
|
155
|
-
@smtp.should_receive(:send_message).with("message", 'from', ['to', 'cc'])
|
156
|
-
Pony.transport_via_smtp(mock('tmail', :to => 'to', :cc => 'cc', :from => 'from', :to_s => 'message', :bcc => nil, :destinations => ['to', 'cc']))
|
157
|
-
end
|
158
|
-
|
159
|
-
it "only pass cc as the list of recipients" do
|
160
|
-
@smtp.should_receive(:send_message).with("message", ['from'], ['to', 'cc' ])
|
161
|
-
Pony.transport_via_smtp(mock('tmail', :to => ['to'], :cc => ['cc'], :from => ['from'], :to_s => 'message', :bcc => nil, :destinations => ['to', 'cc']))
|
162
|
-
end
|
163
|
-
|
164
|
-
it "only pass bcc as the list of recipients" do
|
165
|
-
@smtp.should_receive(:send_message).with("message", ['from'], ['to', 'bcc' ])
|
166
|
-
Pony.transport_via_smtp(mock('tmail', :to => ['to'], :cc => nil, :from => ['from'], :to_s => 'message', :bcc => ['bcc'], :destinations => ['to', 'bcc']))
|
167
|
-
end
|
168
|
-
|
169
|
-
it "passes cc and bcc as the list of recipients when there are a few of them" do
|
170
|
-
@smtp.should_receive(:send_message).with("message", ['from'], ['to', 'to2', 'cc', 'bcc', 'bcc2', 'bcc3'])
|
171
|
-
Pony.transport_via_smtp(mock('tmail', :to => ['to', 'to2'], :cc => ['cc'], :from => ['from'], :to_s => 'message', :bcc => ['bcc', 'bcc2', 'bcc3'], :destinations => ['to', 'to2', 'cc', 'bcc', 'bcc2', 'bcc3']))
|
172
|
-
end
|
173
|
-
|
174
|
-
it "defaults to localhost as the SMTP server" do
|
175
|
-
Net::SMTP.should_receive(:new).with('localhost', '25').and_return(@smtp)
|
176
|
-
Pony.transport_via_smtp(mock('tmail', :to => ['to'], :from => ['from'], :to_s => 'message', :cc => nil, :bcc => nil, :destinations => ['to']))
|
177
|
-
end
|
178
|
-
|
179
|
-
it "uses SMTP authorization when auth key is provided" do
|
180
|
-
o = { :smtp => { :user => 'user', :password => 'password', :auth => 'plain'}}
|
181
|
-
@smtp.should_receive(:start).with('localhost.localdomain', 'user', 'password', 'plain')
|
182
|
-
Pony.transport_via_smtp(mock('tmail', :to => ['to'], :from => ['from'], :to_s => 'message', :cc => nil, :bcc => nil, :destinations => ['to']), o)
|
183
|
-
end
|
184
|
-
|
185
|
-
it "enable starttls when tls option is true" do
|
186
|
-
o = { :smtp => { :user => 'user', :password => 'password', :auth => 'plain', :tls => true}}
|
187
|
-
@smtp.should_receive(:enable_starttls)
|
188
|
-
Pony.transport_via_smtp(mock('tmail', :to => ['to'], :from => ['from'], :to_s => 'message', :cc => nil, :bcc => nil, :destinations => ['to']), o)
|
189
|
-
end
|
190
|
-
|
191
|
-
it "starts the job" do
|
192
|
-
@smtp.should_receive(:start)
|
193
|
-
Pony.transport_via_smtp(mock('tmail', :to => ['to'], :from => ['from'], :to_s => 'message', :cc => nil, :bcc => nil, :destinations => ['to']))
|
194
|
-
end
|
195
|
-
|
196
|
-
it "sends a tmail message" do
|
197
|
-
@smtp.should_receive(:send_message)
|
198
|
-
Pony.transport_via_smtp(mock('tmail', :to => ['to'], :from => ['from'], :to_s => 'message', :cc => nil, :bcc => nil, :destinations => ['to']))
|
199
|
-
end
|
200
|
-
|
201
|
-
it "finishes the job" do
|
202
|
-
@smtp.should_receive(:finish)
|
203
|
-
Pony.transport_via_smtp(mock('tmail', :to => ['to'], :from => ['from'], :to_s => 'message', :cc => nil, :bcc => nil, :destinations => ['to']))
|
204
|
-
end
|
205
|
-
|
206
|
-
end
|
207
|
-
end
|
208
|
-
|
209
|
-
describe ":via option should over-ride the default transport mechanism" do
|
210
|
-
it "should send via sendmail if :via => sendmail" do
|
211
|
-
Pony.should_receive(:transport_via_sendmail)
|
212
|
-
Pony.mail(:to => 'joe@example.com', :via => :sendmail)
|
213
|
-
end
|
214
|
-
|
215
|
-
it "should send via smtp if :via => smtp" do
|
216
|
-
Pony.should_receive(:transport_via_smtp)
|
217
|
-
Pony.mail(:to => 'joe@example.com', :via => :smtp)
|
218
|
-
end
|
219
|
-
|
220
|
-
it "should raise an error if via is neither smtp nor sendmail" do
|
221
|
-
lambda { Pony.mail(:to => 'joe@plumber.com', :via => :pigeon) }.should raise_error(ArgumentError)
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
describe "sendmail binary location" do
|
226
|
-
it "should default to /usr/sbin/sendmail if not in path" do
|
227
|
-
Pony.stub!(:'`').and_return('')
|
228
|
-
Pony.sendmail_binary.should == '/usr/sbin/sendmail'
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
end
|