pony 0.9.1 → 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +53 -34
- data/lib/pony.rb +186 -81
- data/pony.gemspec +2 -3
- data/spec/pony_spec.rb +98 -119
- metadata +8 -22
data/README.rdoc
CHANGED
@@ -5,8 +5,8 @@
|
|
5
5
|
Ruby no longer has to be jealous of PHP's mail() function, which can send an email in a single command.
|
6
6
|
|
7
7
|
Pony.mail(:to => 'you@example.com', :from => 'me@example.com', :subject => 'hi', :body => 'Hello there.')
|
8
|
-
Pony.mail(:to => 'you@example.com', :
|
9
|
-
Pony.mail(:to => 'you@example.com', :cc => 'him@example.com', :from => 'me@example.com', :subject => 'hi', :body => '
|
8
|
+
Pony.mail(:to => 'you@example.com', :html_body => '<h1>Hello there!</h1>', :body => "In case you can't read html, Hello there.")
|
9
|
+
Pony.mail(:to => 'you@example.com', :cc => 'him@example.com', :from => 'me@example.com', :subject => 'hi', :body => 'Howsit!')
|
10
10
|
|
11
11
|
Any option key may be omitted except for :to. For a complete list of options, see List Of Options section below.
|
12
12
|
|
@@ -15,7 +15,7 @@ Any option key may be omitted except for :to. For a complete list of options, se
|
|
15
15
|
|
16
16
|
Pony uses /usr/sbin/sendmail to send mail if it is available, otherwise it uses SMTP to localhost.
|
17
17
|
|
18
|
-
This can be over-ridden if you specify a via option
|
18
|
+
This can be over-ridden if you specify a via option:
|
19
19
|
|
20
20
|
Pony.mail(:to => 'you@example.com', :via => :smtp) # sends via SMTP
|
21
21
|
|
@@ -23,29 +23,34 @@ This can be over-ridden if you specify a via option
|
|
23
23
|
|
24
24
|
You can also specify options for SMTP:
|
25
25
|
|
26
|
-
Pony.mail(:to => 'you@example.com', :via => :smtp, :
|
27
|
-
:
|
28
|
-
:port
|
29
|
-
:
|
30
|
-
:password
|
31
|
-
:
|
32
|
-
:domain
|
26
|
+
Pony.mail(:to => 'you@example.com', :via => :smtp, :via_options => {
|
27
|
+
:address => 'smtp.yourserver.com',
|
28
|
+
:port => '25',
|
29
|
+
:user_name => 'user',
|
30
|
+
:password => 'password',
|
31
|
+
:authentication => :plain, # :plain, :login, :cram_md5, no auth by default
|
32
|
+
:domain => "localhost.localdomain" # the HELO domain provided by the client to the server
|
33
33
|
}
|
34
34
|
|
35
|
-
|
35
|
+
Gmail example (with TLS/SSL)
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
:
|
41
|
-
:
|
42
|
-
:
|
43
|
-
:
|
44
|
-
:
|
45
|
-
:auth => :plain, # :plain, :login, :cram_md5, no auth by default
|
46
|
-
:domain => "localhost.localdomain" # the HELO domain provided by the client to the server
|
37
|
+
Pony.mail(:to => 'you@example.com', :via => :smtp, :via_options => {
|
38
|
+
:address => 'smtp.gmail.com',
|
39
|
+
:port => '587',
|
40
|
+
:enable_starttls_auto => true,
|
41
|
+
:user_name => 'user',
|
42
|
+
:password => 'password',
|
43
|
+
:authentication => :plain, # :plain, :login, :cram_md5, no auth by default
|
44
|
+
:domain => "localhost.localdomain" # the HELO domain provided by the client to the server
|
47
45
|
})
|
48
46
|
|
47
|
+
And options for Sendmail:
|
48
|
+
|
49
|
+
Pony.mail(:to => 'you@example.com', :via => :smtp, :via_options => {
|
50
|
+
:location => '/path/to/sendmail' # this defaults to 'which sendmail' or '/usr/sbin/sendmail' if 'which' fails
|
51
|
+
:arguments => '-t' # -t and -i are the defaults
|
52
|
+
}
|
53
|
+
|
49
54
|
== Attachments
|
50
55
|
|
51
56
|
You can attach a file or two with the :attachments option:
|
@@ -62,32 +67,34 @@ Pony allows you to specify custom mail headers
|
|
62
67
|
:headers => { "List-ID" => "...", "X-My-Custom-Header" => "what a cool custom header" }
|
63
68
|
)
|
64
69
|
|
65
|
-
|
66
70
|
== List Of Options
|
67
71
|
|
68
|
-
Options passed pretty much directly to
|
69
|
-
content_type
|
72
|
+
Options passed pretty much directly to Mail
|
70
73
|
to
|
71
74
|
cc
|
72
75
|
bcc
|
73
76
|
from
|
77
|
+
body # the plain text body
|
78
|
+
html_body # for sending html-formatted email
|
74
79
|
subject
|
75
|
-
charset
|
80
|
+
charset # In case you need to send in utf-8 or similar
|
76
81
|
attachments # see Attachments section above
|
77
82
|
headers # see Custom headers section above
|
78
83
|
message_id
|
79
84
|
|
80
85
|
Other options
|
81
86
|
via # :smtp or :sendmail, see Transport section above
|
82
|
-
|
83
|
-
|
87
|
+
via_options # specify transport options, see Transport section above
|
88
|
+
|
89
|
+
== Help
|
90
|
+
|
91
|
+
If you need help using Pony, or it looks like you've found a bug, we have a google group setup at: ponyrb@googlegroups.com.
|
84
92
|
|
85
93
|
== External Dependencies
|
86
94
|
|
87
|
-
|
88
|
-
mime-types >= 1.16
|
95
|
+
mail > 2.0
|
89
96
|
|
90
|
-
Note: these requirements are specified in the gemspec as well. Also, you may need smtp_tls if you want to send via tls and are using ruby < 1.8.7
|
97
|
+
Note: these requirements are specified in the gemspec as well. Also, you may need smtp_tls if you want to send via tls/ssl and are using ruby < 1.8.7
|
91
98
|
|
92
99
|
== Meta
|
93
100
|
|
@@ -95,9 +102,18 @@ Maintained by Ben Prew
|
|
95
102
|
|
96
103
|
Written by Adam Wiggins
|
97
104
|
|
98
|
-
Patches contributed by:
|
99
|
-
|
100
|
-
|
105
|
+
Patches contributed by:
|
106
|
+
Arun Thampi,
|
107
|
+
Hiroshi Saito,
|
108
|
+
Jesse Cooke,
|
109
|
+
Mathieu Martin,
|
110
|
+
Neil Mock,
|
111
|
+
Nickolas Means,
|
112
|
+
Othmane Benkirane,
|
113
|
+
Rick Olson
|
114
|
+
Stephen Celis,
|
115
|
+
Thomas Hurst,
|
116
|
+
Kalin Harvey
|
101
117
|
|
102
118
|
Released under the MIT License: http://www.opensource.org/licenses/mit-license.php
|
103
119
|
|
@@ -107,13 +123,16 @@ mailing list: ponyrb@googlegroups.com
|
|
107
123
|
|
108
124
|
== Releases
|
109
125
|
|
126
|
+
1.0
|
127
|
+
* Convert to using Mail as the mail-generation backend, instead of TMail
|
128
|
+
|
110
129
|
0.9.1
|
111
130
|
* provide the ability to set custom mail headers with something like:
|
112
131
|
Pony.mail(:headers => {"List-ID" => "..."})
|
113
132
|
* provide the ability to set the Message-Id from Pony.mail
|
114
133
|
|
115
134
|
0.9
|
116
|
-
* merge in
|
135
|
+
* merge in kalin's fixes to use tmail.destinations instead of trying to parse tmail.to, tmail.cc and tmail.bcc. New specs to test functionality
|
117
136
|
|
118
137
|
0.8
|
119
138
|
* Fix bug that was allowing nil :bcc and :cc options to be passed to smtp
|
data/lib/pony.rb
CHANGED
@@ -1,65 +1,199 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require '
|
3
|
-
require 'mime/types'
|
4
|
-
begin
|
5
|
-
require 'smtp_tls'
|
6
|
-
rescue LoadError
|
7
|
-
end
|
2
|
+
require 'mail'
|
8
3
|
require 'base64'
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
4
|
+
|
5
|
+
# = Pony, the express way to send email in Ruby
|
6
|
+
#
|
7
|
+
# == Overview
|
8
|
+
#
|
9
|
+
# Ruby no longer has to be jealous of PHP's mail() function, which can send an email in a single command.
|
10
|
+
#
|
11
|
+
# Pony.mail(:to => 'you@example.com', :from => 'me@example.com', :subject => 'hi', :body => 'Hello there.')
|
12
|
+
# Pony.mail(:to => 'you@example.com', :html_body => '<h1>Hello there!</h1>', :body => "In case you can't read html, Hello there.")
|
13
|
+
# Pony.mail(:to => 'you@example.com', :cc => 'him@example.com', :from => 'me@example.com', :subject => 'hi', :body => 'Howsit!')
|
14
|
+
#
|
15
|
+
# Any option key may be omitted except for :to. For a complete list of options, see List Of Options section below.
|
16
|
+
#
|
17
|
+
#
|
18
|
+
# == Transport
|
19
|
+
#
|
20
|
+
# Pony uses /usr/sbin/sendmail to send mail if it is available, otherwise it uses SMTP to localhost.
|
21
|
+
#
|
22
|
+
# This can be over-ridden if you specify a via option:
|
23
|
+
#
|
24
|
+
# Pony.mail(:to => 'you@example.com', :via => :smtp) # sends via SMTP
|
25
|
+
#
|
26
|
+
# Pony.mail(:to => 'you@example.com', :via => :sendmail) # sends via sendmail
|
27
|
+
#
|
28
|
+
# You can also specify options for SMTP:
|
29
|
+
#
|
30
|
+
# Pony.mail(:to => 'you@example.com', :via => :smtp, :via_options => {
|
31
|
+
# :address => 'smtp.yourserver.com',
|
32
|
+
# :port => '25',
|
33
|
+
# :user_name => 'user',
|
34
|
+
# :password => 'password',
|
35
|
+
# :authentication => :plain, # :plain, :login, :cram_md5, no auth by default
|
36
|
+
# :domain => "localhost.localdomain" # the HELO domain provided by the client to the server
|
37
|
+
# }
|
38
|
+
#
|
39
|
+
# Gmail example (with TLS/SSL)
|
40
|
+
#
|
41
|
+
# Pony.mail(:to => 'you@example.com', :via => :smtp, :via_options => {
|
42
|
+
# :address => 'smtp.gmail.com',
|
43
|
+
# :port => '587',
|
44
|
+
# :enable_starttls_auto => true,
|
45
|
+
# :user_name => 'user',
|
46
|
+
# :password => 'password',
|
47
|
+
# :authentication => :plain, # :plain, :login, :cram_md5, no auth by default
|
48
|
+
# :domain => "localhost.localdomain" # the HELO domain provided by the client to the server
|
49
|
+
# })
|
50
|
+
#
|
51
|
+
# And options for Sendmail:
|
52
|
+
#
|
53
|
+
# Pony.mail(:to => 'you@example.com', :via => :smtp, :via_options => {
|
54
|
+
# :location => '/path/to/sendmail' # this defaults to 'which sendmail' or '/usr/sbin/sendmail' if 'which' fails
|
55
|
+
# :arguments => '-t' # -t and -i are the defaults
|
56
|
+
# }
|
57
|
+
#
|
58
|
+
# == Attachments
|
59
|
+
#
|
60
|
+
# You can attach a file or two with the :attachments option:
|
61
|
+
#
|
62
|
+
# Pony.mail(..., :attachments => {"foo.zip" => File.read("path/to/foo.zip"), "hello.txt" => "hello!"})
|
63
|
+
#
|
64
|
+
# Note: An attachment's mime-type is set based on the filename (as dictated by the ruby gem mime-types). So 'foo.pdf' has a mime-type of 'application/pdf'
|
65
|
+
#
|
66
|
+
# == Custom Headers
|
67
|
+
#
|
68
|
+
# Pony allows you to specify custom mail headers
|
69
|
+
# Pony.mail(
|
70
|
+
# :to => 'me@example.com',
|
71
|
+
# :headers => { "List-ID" => "...", "X-My-Custom-Header" => "what a cool custom header" }
|
72
|
+
# )
|
73
|
+
#
|
74
|
+
# == List Of Options
|
75
|
+
#
|
76
|
+
# Options passed pretty much directly to Mail
|
77
|
+
# to
|
78
|
+
# cc
|
79
|
+
# bcc
|
80
|
+
# from
|
81
|
+
# body # the plain text body
|
82
|
+
# html_body # for sending html-formatted email
|
83
|
+
# subject
|
84
|
+
# charset # In case you need to send in utf-8 or similar
|
85
|
+
# attachments # see Attachments section above
|
86
|
+
# headers # see Custom headers section above
|
87
|
+
# message_id
|
88
|
+
#
|
89
|
+
# Other options
|
90
|
+
# via # :smtp or :sendmail, see Transport section above
|
91
|
+
# via_options # specify transport options, see Transport section above
|
92
|
+
|
93
|
+
|
14
94
|
|
15
95
|
module Pony
|
96
|
+
|
97
|
+
# Send an email
|
98
|
+
# Pony.mail(:to => 'you@example.com', :from => 'me@example.com', :subject => 'hi', :body => 'Hello there.')
|
99
|
+
# Pony.mail(:to => 'you@example.com', :html_body => '<h1>Hello there!</h1>', :body => "In case you can't read html, Hello there.")
|
100
|
+
# Pony.mail(:to => 'you@example.com', :cc => 'him@example.com', :from => 'me@example.com', :subject => 'hi', :body => 'Howsit!')
|
16
101
|
def self.mail(options)
|
17
102
|
raise(ArgumentError, ":to is required") unless options[:to]
|
18
103
|
|
19
|
-
via = options.
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
104
|
+
options[:via] = default_delivery_method unless options.has_key?(:via)
|
105
|
+
raise(ArgumentError, ":via must be either smtp or sendmail") unless via_possibilities.include?(options[:via])
|
106
|
+
|
107
|
+
options = cross_reference_depricated_fields(options)
|
108
|
+
|
109
|
+
if options.has_key?(:via) && options[:via] == :sendmail
|
110
|
+
options[:via_options] ||= {}
|
111
|
+
options[:via_options][:location] ||= sendmail_binary
|
112
|
+
end
|
113
|
+
|
114
|
+
deliver build_mail(options)
|
115
|
+
end
|
116
|
+
|
117
|
+
private
|
118
|
+
|
119
|
+
def self.cross_reference_depricated_fields(options)
|
120
|
+
if options.has_key?(:smtp)
|
121
|
+
warn depricated_message(:smtp, :via_options)
|
122
|
+
options[:via_options] = options.delete(:smtp)
|
123
|
+
end
|
124
|
+
|
125
|
+
# cross-reference pony options to be compatible with keys mail expects
|
126
|
+
{ :host => :address, :user => :user_name, :auth => :authentication, :tls => :enable_starttls_auto }.each do |key, val|
|
127
|
+
if options[:via_options] && options[:via_options].has_key?(key)
|
128
|
+
warn depricated_message(key, val)
|
129
|
+
options[:via_options][val] = options[:via_options].delete(key)
|
27
130
|
end
|
28
131
|
end
|
132
|
+
|
133
|
+
if options[:content_type] && options[:content_type] =~ /html/ && !options[:html_body]
|
134
|
+
warn depricated_message(:content_type, :html_body)
|
135
|
+
options[:html_body] = options[:body]
|
136
|
+
end
|
137
|
+
|
138
|
+
return options
|
29
139
|
end
|
30
140
|
|
31
|
-
def self.
|
32
|
-
mail
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
141
|
+
def self.deliver(mail)
|
142
|
+
mail.deliver!
|
143
|
+
end
|
144
|
+
|
145
|
+
def self.default_delivery_method
|
146
|
+
File.executable?(sendmail_binary) ? :sendmail : :smtp
|
147
|
+
end
|
148
|
+
|
149
|
+
def self.build_mail(options)
|
150
|
+
mail = Mail.new do
|
151
|
+
to options[:to]
|
152
|
+
from options[:from] || 'pony@unknown'
|
153
|
+
cc options[:cc]
|
154
|
+
bcc options[:bcc]
|
155
|
+
subject options[:subject]
|
156
|
+
date options[:date] || Time.now
|
157
|
+
message_id options[:message_id]
|
158
|
+
|
159
|
+
if options[:html_body]
|
160
|
+
html_part do
|
161
|
+
content_type 'text/html; charset=UTF-8'
|
162
|
+
body options[:html_body]
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
# If we're using attachments, the body needs to be a separate part. If not,
|
167
|
+
# we can just set the body directly.
|
168
|
+
if options[:body] && (options[:html_body] || options[:attachments])
|
169
|
+
text_part do
|
170
|
+
body options[:body]
|
171
|
+
end
|
172
|
+
elsif options[:body]
|
173
|
+
body options[:body]
|
174
|
+
end
|
175
|
+
|
176
|
+
delivery_method options[:via], (options.has_key?(:via_options) ? options[:via_options] : {})
|
177
|
+
end
|
178
|
+
|
179
|
+
(options[:attachments] || []).each do |name, body|
|
180
|
+
# mime-types wants to send these as "quoted-printable"
|
181
|
+
if name =~ /\.xlsx$/
|
182
|
+
mail.attachments[name] = {
|
183
|
+
:content => Base64.encode64(body),
|
184
|
+
:transfer_encoding => :base64
|
185
|
+
}
|
186
|
+
else
|
187
|
+
mail.attachments[name] = body
|
54
188
|
end
|
55
|
-
else
|
56
|
-
mail.content_type = options[:content_type] || "text/plain"
|
57
|
-
mail.body = options[:body] || ""
|
58
189
|
end
|
190
|
+
|
59
191
|
(options[:headers] ||= {}).each do |key, value|
|
60
192
|
mail[key] = value
|
61
193
|
end
|
62
|
-
|
194
|
+
|
195
|
+
mail.charset = options[:charset] if options[:charset] # charset must be set after setting content_type
|
196
|
+
|
63
197
|
mail
|
64
198
|
end
|
65
199
|
|
@@ -68,42 +202,13 @@ module Pony
|
|
68
202
|
sendmail.empty? ? '/usr/sbin/sendmail' : sendmail
|
69
203
|
end
|
70
204
|
|
71
|
-
def self.
|
72
|
-
|
73
|
-
transport_via_sendmail(tmail)
|
74
|
-
else
|
75
|
-
transport_via_smtp(tmail)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
def self.via_options
|
80
|
-
%w(sendmail smtp)
|
81
|
-
end
|
82
|
-
|
83
|
-
def self.transport_via_sendmail(tmail, options={})
|
84
|
-
IO.popen('-', 'w+') do |pipe|
|
85
|
-
if pipe
|
86
|
-
pipe.write(tmail.to_s)
|
87
|
-
else
|
88
|
-
exec(sendmail_binary, "-t")
|
89
|
-
end
|
90
|
-
end
|
205
|
+
def self.via_possibilities
|
206
|
+
%w(sendmail smtp).map{ |x| x.to_sym }
|
91
207
|
end
|
92
208
|
|
93
|
-
def self.
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
if o[:tls]
|
98
|
-
raise "You may need: gem install smtp_tls" unless smtp.respond_to?(:enable_starttls)
|
99
|
-
smtp.enable_starttls
|
100
|
-
end
|
101
|
-
if o.include?(:auth)
|
102
|
-
smtp.start(o[:domain], o[:user], o[:password], o[:auth])
|
103
|
-
else
|
104
|
-
smtp.start(o[:domain])
|
105
|
-
end
|
106
|
-
smtp.send_message tmail.to_s, tmail.from, tmail.destinations
|
107
|
-
smtp.finish
|
209
|
+
def self.depricated_message(method, alternative)
|
210
|
+
warning_message = "warning: '#{method}' is deprecated"
|
211
|
+
warning_message += "; use '#{alternative}' instead." if alternative
|
212
|
+
return warning_message
|
108
213
|
end
|
109
214
|
end
|
data/pony.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{pony}
|
5
|
-
s.version = "0
|
5
|
+
s.version = "1.0"
|
6
6
|
|
7
7
|
s.description = "Send email in one command: Pony.mail(:to => 'someone@example.com', :body => 'hello')"
|
8
8
|
s.summary = s.description
|
@@ -17,7 +17,6 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.rdoc_options = ["--inline-source", "--charset=UTF-8"]
|
18
18
|
s.require_paths = ["lib"]
|
19
19
|
s.rubygems_version = %q{1.3.1}
|
20
|
-
|
21
|
-
s.add_dependency('mime-types', '>= 1.16')
|
20
|
+
s.add_dependency( 'mail', '>2.0')
|
22
21
|
s.platform = Gem::Platform::RUBY
|
23
22
|
end
|
data/spec/pony_spec.rb
CHANGED
@@ -1,220 +1,192 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
1
2
|
require File.dirname(__FILE__) + '/base'
|
2
3
|
|
3
4
|
describe Pony do
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
Pony.stub!(:deliver)
|
8
|
+
end
|
9
|
+
|
4
10
|
it "sends mail" do
|
5
|
-
Pony.should_receive(:
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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.'
|
10
16
|
end
|
11
17
|
Pony.mail(:to => 'joe@example.com', :from => 'sender@example.com', :subject => 'hi', :body => 'Hello, Joe.')
|
12
18
|
end
|
13
19
|
|
14
20
|
it "requires :to param" do
|
15
|
-
Pony.stub!(:transport)
|
16
21
|
lambda { Pony.mail({}) }.should raise_error(ArgumentError)
|
17
22
|
end
|
18
23
|
|
19
24
|
it "doesn't require any other param" do
|
20
|
-
Pony.stub!(:transport)
|
21
25
|
lambda { Pony.mail(:to => 'joe@example.com') }.should_not raise_error
|
22
26
|
end
|
23
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' })
|
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
|
24
37
|
####################
|
25
38
|
|
26
|
-
describe "builds a
|
39
|
+
describe "builds a Mail object with field:" do
|
27
40
|
it "to" do
|
28
|
-
Pony.
|
41
|
+
Pony.build_mail(:to => 'joe@example.com').to.should == [ 'joe@example.com' ]
|
29
42
|
end
|
30
43
|
|
31
44
|
it "to with multiple recipients" do
|
32
|
-
Pony.
|
45
|
+
Pony.build_mail(:to => 'joe@example.com, friedrich@example.com').to.should == [ 'joe@example.com', 'friedrich@example.com' ]
|
33
46
|
end
|
34
47
|
|
35
48
|
it "to with multiple recipients and names" do
|
36
|
-
Pony.
|
49
|
+
Pony.build_mail(:to => 'joe@example.com, "Friedrich Hayek" <friedrich@example.com>').to.should == [ 'joe@example.com', 'friedrich@example.com' ]
|
37
50
|
end
|
38
51
|
|
39
52
|
it "to with multiple recipients and names in an array" do
|
40
|
-
Pony.
|
53
|
+
Pony.build_mail(:to => ['joe@example.com', '"Friedrich Hayek" <friedrich@example.com>']).to.should == [ 'joe@example.com', 'friedrich@example.com' ]
|
41
54
|
end
|
42
55
|
|
43
56
|
it "cc" do
|
44
|
-
Pony.
|
57
|
+
Pony.build_mail(:cc => 'joe@example.com').cc.should == [ 'joe@example.com' ]
|
45
58
|
end
|
46
59
|
|
47
60
|
it "cc with multiple recipients" do
|
48
|
-
Pony.
|
61
|
+
Pony.build_mail(:cc => 'joe@example.com, friedrich@example.com').cc.should == [ 'joe@example.com', 'friedrich@example.com' ]
|
49
62
|
end
|
50
63
|
|
51
64
|
it "from" do
|
52
|
-
Pony.
|
65
|
+
Pony.build_mail(:from => 'joe@example.com').from.should == [ 'joe@example.com' ]
|
53
66
|
end
|
54
67
|
|
55
68
|
it "bcc" do
|
56
|
-
Pony.
|
69
|
+
Pony.build_mail(:bcc => 'joe@example.com').bcc.should == [ 'joe@example.com' ]
|
57
70
|
end
|
58
71
|
|
59
72
|
it "bcc with multiple recipients" do
|
60
|
-
Pony.
|
73
|
+
Pony.build_mail(:bcc => 'joe@example.com, friedrich@example.com').bcc.should == [ 'joe@example.com', 'friedrich@example.com' ]
|
61
74
|
end
|
62
75
|
|
63
76
|
it "charset" do
|
64
|
-
Pony.
|
77
|
+
mail = Pony.build_mail(:charset => 'UTF-8')
|
78
|
+
mail.charset.should == 'UTF-8'
|
65
79
|
end
|
66
80
|
|
67
81
|
it "default charset" do
|
68
|
-
Pony.
|
69
|
-
Pony.
|
82
|
+
Pony.build_mail(:body => 'body').charset.should == 'UTF-8'
|
83
|
+
Pony.build_mail(:body => 'body', :content_type => 'text/html').charset.should == 'UTF-8'
|
70
84
|
end
|
71
85
|
|
72
86
|
it "from (default)" do
|
73
|
-
Pony.
|
87
|
+
Pony.build_mail({}).from.should == [ 'pony@unknown' ]
|
74
88
|
end
|
75
89
|
|
76
90
|
it "subject" do
|
77
|
-
Pony.
|
91
|
+
Pony.build_mail(:subject => 'hello').subject.should == 'hello'
|
78
92
|
end
|
79
93
|
|
80
94
|
it "body" do
|
81
|
-
Pony.
|
95
|
+
Pony.build_mail(:body => 'What do you know, Joe?').body.should == 'What do you know, Joe?'
|
82
96
|
end
|
83
97
|
|
84
|
-
it "
|
85
|
-
Pony.
|
98
|
+
it "html_body" do
|
99
|
+
Pony.build_mail(:html_body => 'What do you know, Joe?').parts.first.body.should == 'What do you know, Joe?'
|
100
|
+
Pony.build_mail(:html_body => 'What do you know, Joe?').parts.first.content_type.should == 'text/html; charset=UTF-8'
|
101
|
+
end
|
102
|
+
|
103
|
+
it "date" do
|
104
|
+
now = Time.now
|
105
|
+
Pony.build_mail(:date => now).date.should == DateTime.parse(now.to_s)
|
106
|
+
end
|
107
|
+
|
108
|
+
it "content_type of html should set html_body" do
|
109
|
+
Pony.should_receive(:build_mail).with(hash_including(:html_body => '<h1>test</h1>'))
|
110
|
+
Pony.mail(:to => 'foo@bar', :content_type => 'text/html', :body => '<h1>test</h1>')
|
86
111
|
end
|
87
112
|
|
88
113
|
it "message_id" do
|
89
|
-
Pony.
|
114
|
+
Pony.build_mail(:message_id => '<abc@def.com>').message_id.should == 'abc@def.com'
|
90
115
|
end
|
91
116
|
|
92
117
|
it "custom headers" do
|
93
|
-
Pony.
|
118
|
+
Pony.build_mail(:headers => {"List-ID" => "<abc@def.com>"})['List-ID'].to_s.should == '<abc@def.com>'
|
94
119
|
end
|
95
120
|
|
96
|
-
it "
|
97
|
-
|
98
|
-
|
99
|
-
|
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
|
121
|
+
it "utf-8 encoded subject line" do
|
122
|
+
mail = Pony.build_mail(:to => 'btp@foo', :subject => 'Café', :body => 'body body body')
|
123
|
+
mail['subject'].encoded.should =~ /^Subject: =\?UTF-8/;
|
124
|
+
end
|
104
125
|
|
105
|
-
|
106
|
-
|
126
|
+
it "attachments" do
|
127
|
+
mail = Pony.build_mail(:attachments => {"foo.txt" => "content of foo.txt"}, :body => 'test')
|
128
|
+
mail.parts.length.should == 2
|
129
|
+
mail.parts.first.to_s.should =~ /Content-Type: text\/plain/
|
107
130
|
end
|
108
131
|
|
109
132
|
it "suggests mime-type" do
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
Content-Disposition: attachment; filename=foo.pdf
|
133
|
+
mail = Pony.build_mail(:attachments => {"foo.pdf" => "content of foo.pdf"})
|
134
|
+
mail.parts.length.should == 1
|
135
|
+
mail.parts.first.to_s.should =~ /Content-Type: application\/pdf/
|
136
|
+
mail.parts.first.to_s.should =~ /filename=foo.pdf/
|
137
|
+
mail.parts.first.content_transfer_encoding.to_s.should == 'base64'
|
138
|
+
end
|
117
139
|
|
118
|
-
|
119
|
-
|
140
|
+
it "encodes xlsx files as base64" do
|
141
|
+
mail = Pony.build_mail(:attachments => {"foo.xlsx" => "content of foo.xlsx"})
|
142
|
+
mail.parts.length.should == 1
|
143
|
+
mail.parts.first.to_s.should =~ /Content-Type: application\/vnd.openxmlformats-officedocument.spreadsheetml.sheet/
|
144
|
+
mail.parts.first.to_s.should =~ /filename=foo.xlsx/
|
145
|
+
mail.parts.first.content_transfer_encoding.to_s.should == 'base64'
|
120
146
|
end
|
121
|
-
end
|
122
147
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
Pony.should_receive(:transport_via_sendmail).with(:tmail)
|
127
|
-
Pony.transport(:tmail)
|
148
|
+
it "passes cc and bcc as the list of recipients" do
|
149
|
+
mail = Pony.build_mail(:to => ['to'], :cc => ['cc'], :from => ['from'], :bcc => ['bcc'])
|
150
|
+
mail.destinations.should == ['to', 'cc', 'bcc']
|
128
151
|
end
|
152
|
+
end
|
129
153
|
|
154
|
+
describe "transport" do
|
130
155
|
it "transports via smtp if no sendmail binary" do
|
131
156
|
Pony.stub!(:sendmail_binary).and_return('/does/not/exist')
|
132
|
-
Pony.should_receive(:
|
133
|
-
Pony.
|
157
|
+
Pony.should_receive(:build_mail).with(hash_including(:via => :smtp))
|
158
|
+
Pony.mail(:to => 'foo@bar')
|
134
159
|
end
|
135
160
|
|
136
|
-
it "
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
Pony.transport_via_sendmail(mock('tmail', :to => ['to'], :from => ['from'], :to_s => 'message'))
|
161
|
+
it "defaults to sendmail if no via is specified and sendmail exists" do
|
162
|
+
File.stub!(:executable?).and_return(true)
|
163
|
+
Pony.should_receive(:build_mail).with(hash_including(:via => :sendmail))
|
164
|
+
Pony.mail(:to => 'foo@bar')
|
141
165
|
end
|
142
166
|
|
143
167
|
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
168
|
|
174
169
|
it "defaults to localhost as the SMTP server" do
|
175
|
-
|
176
|
-
|
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)
|
170
|
+
mail = Pony.build_mail(:to => "foo@bar", :enable_starttls_auto => true, :via => :smtp)
|
171
|
+
mail.delivery_method.settings[:address].should == 'localhost'
|
183
172
|
end
|
184
173
|
|
185
174
|
it "enable starttls when tls option is true" do
|
186
|
-
|
187
|
-
|
188
|
-
Pony.transport_via_smtp(mock('tmail', :to => ['to'], :from => ['from'], :to_s => 'message', :cc => nil, :bcc => nil, :destinations => ['to']), o)
|
175
|
+
mail = Pony.build_mail(:to => "foo@bar", :enable_starttls_auto => true, :via => :smtp)
|
176
|
+
mail.delivery_method.settings[:enable_starttls_auto].should == true
|
189
177
|
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
178
|
end
|
207
179
|
end
|
208
180
|
|
209
181
|
describe ":via option should over-ride the default transport mechanism" do
|
210
182
|
it "should send via sendmail if :via => sendmail" do
|
211
|
-
Pony.
|
212
|
-
|
183
|
+
mail = Pony.build_mail(:to => 'joe@example.com', :via => :sendmail)
|
184
|
+
mail.delivery_method.kind_of?(Mail::Sendmail).should == true
|
213
185
|
end
|
214
186
|
|
215
187
|
it "should send via smtp if :via => smtp" do
|
216
|
-
Pony.
|
217
|
-
|
188
|
+
mail = Pony.build_mail(:to => 'joe@example.com', :via => :smtp)
|
189
|
+
mail.delivery_method.kind_of?(Mail::SMTP).should == true
|
218
190
|
end
|
219
191
|
|
220
192
|
it "should raise an error if via is neither smtp nor sendmail" do
|
@@ -222,6 +194,13 @@ Y29udGVudCBvZiBmb28ucGRm
|
|
222
194
|
end
|
223
195
|
end
|
224
196
|
|
197
|
+
describe "via_possibilities" do
|
198
|
+
it "should contain smtp and sendmail" do
|
199
|
+
Pony.via_possibilities.should == [:sendmail, :smtp]
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
|
225
204
|
describe "sendmail binary location" do
|
226
205
|
it "should default to /usr/sbin/sendmail if not in path" do
|
227
206
|
Pony.stub!(:'`').and_return('')
|
metadata
CHANGED
@@ -3,10 +3,9 @@ name: pony
|
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
|
-
- 0
|
7
|
-
- 9
|
8
6
|
- 1
|
9
|
-
|
7
|
+
- 0
|
8
|
+
version: "1.0"
|
10
9
|
platform: ruby
|
11
10
|
authors:
|
12
11
|
- Adam Wiggins
|
@@ -15,35 +14,22 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2010-
|
17
|
+
date: 2010-05-07 00:00:00 -06:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
|
-
name:
|
21
|
+
name: mail
|
23
22
|
prerelease: false
|
24
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
24
|
requirements:
|
26
|
-
- -
|
25
|
+
- - ">"
|
27
26
|
- !ruby/object:Gem::Version
|
28
27
|
segments:
|
29
|
-
-
|
28
|
+
- 2
|
30
29
|
- 0
|
31
|
-
version: "
|
30
|
+
version: "2.0"
|
32
31
|
type: :runtime
|
33
32
|
version_requirements: *id001
|
34
|
-
- !ruby/object:Gem::Dependency
|
35
|
-
name: mime-types
|
36
|
-
prerelease: false
|
37
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
-
requirements:
|
39
|
-
- - ">="
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
segments:
|
42
|
-
- 1
|
43
|
-
- 16
|
44
|
-
version: "1.16"
|
45
|
-
type: :runtime
|
46
|
-
version_requirements: *id002
|
47
33
|
description: "Send email in one command: Pony.mail(:to => 'someone@example.com', :body => 'hello')"
|
48
34
|
email: ben.prew@gmail.com
|
49
35
|
executables: []
|
@@ -57,8 +43,8 @@ files:
|
|
57
43
|
- Rakefile
|
58
44
|
- pony.gemspec
|
59
45
|
- lib/pony.rb
|
60
|
-
- spec/base.rb
|
61
46
|
- spec/pony_spec.rb
|
47
|
+
- spec/base.rb
|
62
48
|
has_rdoc: true
|
63
49
|
homepage: http://github.com/benprew/pony
|
64
50
|
licenses: []
|