mailfactory 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mailfactory.rb +2 -2
- data/tests/test_mailfactory.rb +17 -1
- metadata +1 -1
data/lib/mailfactory.rb
CHANGED
@@ -254,10 +254,10 @@ class MailFactory
|
|
254
254
|
if(!file.respond_to?(:stat) and type == nil)
|
255
255
|
attachment[1] = MIME::Types.type_for(file.to_s()).to_s
|
256
256
|
else
|
257
|
-
|
257
|
+
attachment[1] = type
|
258
258
|
end
|
259
259
|
|
260
|
-
if(file.respond_to?(:stat))
|
260
|
+
if(!file.respond_to?(:stat))
|
261
261
|
# Open in rb mode to handle Windows, which mangles binary files opened in a text mode
|
262
262
|
File.open(file.to_s(), "rb") { |fp|
|
263
263
|
attachment[2] = Base64.b64encode(fp.read())
|
data/tests/test_mailfactory.rb
CHANGED
@@ -151,7 +151,23 @@ class TC_MailFactory < Test::Unit::TestCase
|
|
151
151
|
end
|
152
152
|
|
153
153
|
|
154
|
-
def
|
154
|
+
def test_attach_as
|
155
|
+
@mail.to="test@test.com"
|
156
|
+
@mail.from="test@othertest.com"
|
157
|
+
@mail.subject="This is a test"
|
158
|
+
@mail.text = "This is a test message with\na few\n\nlines."
|
159
|
+
|
160
|
+
@mail.add_attachment_as('testfile.txt', 'newname.txt')
|
161
|
+
@mail.add_attachment_as(File.open('testsheet.xls', 'rb'), 'newname.xls', 'application/vnd.ms-excel')
|
162
|
+
|
163
|
+
if($options['smtpserver'] != nil and $options['to'] != nil and $options['from'] != nil)
|
164
|
+
assert_nothing_raised() {
|
165
|
+
require('net/smtp')
|
166
|
+
Net::SMTP.start($options['smtpserver'], 25, 'mail.from.domain', $options['username'], $options['password'], :cram_md5) { |smtp|
|
167
|
+
smtp.send_message(@mail.to_s(), $options['from'], $options['to'])
|
168
|
+
}
|
169
|
+
}
|
170
|
+
end
|
155
171
|
end
|
156
172
|
|
157
173
|
end
|